Tip & How-To about Computers & Internet

[Linux] How to create a List of files in a directory with neccssary fields

OS: Any Linux / Unix Systems
Purpose : To create a text file containing a list of contents of a directory in specific manner.
Mode of Operation: Command Line Interface
#################################################################

hi...

We often need to create List of contents in a directory, such as , for a Personal Work Logs where each entry represents the activity on a specific day.

We can create File list quickly and easily in Linux and use it to find specific files quickly.

Though there are several methods and several commands , we only focus on easy way , which need to use two commands - cd , ls
cd - [Change Directory] changes the current working directory to specified directory.
USAGE: cd
For more details, Type " man cd " on Terminal or visit here

ls - [LiSt] This command lists the contents. This command supports many options which will customize the output
USAGE: ls
For More Details , Type " man ls " on Terminal or visit here

##############################################################
STEPS

  1. First we need to open a Terminal ( Shell / Bash ).
    You can find shortcut to execute Terminal in Application Menu.
    In Ubuntu shortcut to open terminal is [Ctrl] + [Alt] + [T] or press [Alt] + [F2] to open Run and type " gnome-terminal "
    Or you can get a terminal by Pressing [Ctrl} + [Alt] + [F1] ~ [F6]
    A typical Terminal may look like this

    So now we have a terminal to work with. :-)

  2. Now we need to change current working folder location (In most cases its user's home directory. In my case its /home//Documents) to the folder, of which contents should be listed.
    you can view current working directory by the help of command. Type pwd and press [Enter]
    For this we can use cd command.
    Say, your folder whose contents should be listed is " Source " and is located in " /home/Documents/ " then you should type as

    cd /home/Documents/Source and press [Enter]

    For example, i need to create a list of my English video song collection ( My English songs are located on /media/FUNCLUB/2.VIDEO SONGS/ENGLISH ) , then i would type first:

    cd /media/FUNCLUB/2.VIDEO SONGS/ENGLISH

    To confirm working directory is changed properly, type " pwd " and press [Enter]. It should display our folder.


  3. Now type ' ls ' and press [Enter]. Then it should display folder's contents.

    If you can see contents of folder , everything is working well.

  4. Now need to tell ls how the contents should by displayed. There a lots of formats ls supports. Commonly used formats are
    • ls -l Display contents in detailed List View

      In Order Permissions Owner Group Size in Bytes Created On File Name

    • ls -h Tell ls to display sizes in human readable format (KB, Mb, GB etc.)
      This option uses in conjunction with other options like -l, -s etc


    • ls -s Display File name and its contents. Usually with -h


    • There are a lot more options to control the output format of ls command. To find more about this, please visit here.

  5. We have learned how to format output of ' ls '.
    ' ls ' command outputs to the standard Output (STDOUT) of computer, which is most commonly the monitor itself. Now all we need to save the screen prints to a file so that we can view results later.
    Here what we do is to transfer the output produced by ls command to a file. This is done by " > " ( 'Greater Than' Symbol ).
    'Character' - ' Purpose '
    ' > ' - Transfer the output from STDOUT to file
    ' >> ' - Append the output to specified file (Add the output to end of file)


    Usage:
    ls [Options] >[File]

    example:

    ls -sh >/home/nightflare/Desktop/List_Of_Video_files.txt

Posted by on

Computers & Internet Logo

Related Topics:

Related Questions:

1 Answer

HOW CAN I PRINT FOLDER CONTENTS SIMILLAR TO THE DOS CAOMMAND TREE > PRN


Go to start button. In the start menu click RUN and in the box that opens type "cmd"
In the CLI go to the directory of the folder whose content you want to print and type the following and press enter to create list.txt file first before printing.

dir /b /s /on >list.txt

This will give you a text file (list.txt) in the folder, that you
can manipulate, print etc. in a text editor or
word processor. In order to redirect the output
directly to your printer, instead of a text file, type:

dir /b /s /on >prn

Aug 25, 2010 | Microsoft Computers & Internet

1 Answer

I've been exporting master tracks and now I've reached a point where the tascam says, "master track too big". how do I free up space on the FAT partition?


If you NO LONGER NEED the songs/data in the FAT partition, you can delete the entire contents thereof in the manner detailed below. Note that these instructions were taken directly from the Neo manual.

1 With the transport stopped, from the DISK menu, highlight FAT REFORM, and press YES/ENTER.
2 A pop-up message appears.
3 Ask yourself once more if you want to erase all the data on the FAT partition. Press YES/ENTER to continue with the operation when a pop-up appears, or press NO/EXIT to halt the operation.
4 When you reformat the FAT partition, four directories (folders) named WAVE, SMF, BACKUP and UTILITY are automatically created. These folders are used for audio files, Standard MIDI Files (SMF) and backup data and system utilities, respectively.

...this will reformat and thereby EMPTY the contents of the FAT partition and create the 4 new, empty files as listed above.

THINK before you do this though, and I hope this helps.


Feb 07, 2010 | Tascam 2488 Portastudio Multitrack...

3 Answers

What is the difference between unix and linux


UNIX is a operating system which has only command user interface, and if the unix is installed in the system you cant install any other operating system after that ... one separate system must be allocated for the unix ...

LINUX is the graphical user interface and it supports multiple operating system ..

UNIX and LINUX are almost same, almost all commands which supports in UNIX supports in LINUX too .. with some extended features just like GUI(GRAPHICAL USER INTERFACE),SECURITY,MULTI USER,MULTI TASKING,etc

COMMAND USER INTERFACE - the input is made to the computer by using commands and the output is obtained by command or by printer ...

GRAPHICAL USER INTERFACE- the input is provided to the computer through the other input devices like mouse,joystick etc
the input is provided either by command or by the just clicking the mouse on the particular icon ...

example for graphical user interface is windows,Macintosh etc ...


thank you
bye
any doubts you can reply me
i am always here to assist you
please rate my solution

Aug 19, 2008 | Microsoft Windows Server Standard 2003 for...

1 Answer

Domain problem


Linux and UNIX smbclient command help This option has not been seriously tested and may have some problems.


Getting into Windows Safe Mode Directory Services Restore Mode (Windows domain controllers only).

Linux and UNIX wget command help.

Good Luck, Please dont for get to Vote/Thank You.

Dec 22, 2007 | Microsoft Windows Server Standard 2003 for...

Not finding what you are looking for?

225 people viewed this tip

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Doctor PC
Doctor PC

Level 3 Expert

7733 Answers

kakima

Level 3 Expert

102366 Answers

David Payne
David Payne

Level 3 Expert

14161 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Loading...