Skip to content

Browsing files

Andrea Telatin edited this page Dec 3, 2019 · 10 revisions

Listing files

The general syntax is: ls [options] [files]. Both the options and the files are optional, and files can be files of directories. Now we introduce some of the options: Option Description

  • -a Also show hidden files
  • -l Long format, will show one file per line, with size, owner, date…
  • -h Used with -l, will display file size in human readable format (e.g. 2.3Mb instead of 2298011 )
  • -d Show directories as files, without listing their content

The options can be combined together, the following two commands are identical:

ls -l -h -a
ls -lha

If we want to list the files present at the root, we don't need to move there, but simply ask ls which path to scan for you:

ls /

Here another example:

ls /homes/qib/examples/

You can type as many paths (files or directories) as needed in a single ls command:

ls -l ~/.bashrc ~/.screenrc /homes/qib/examples/

Using the "shell expansion": wildcards to select multiple files

As we noticed, ls can receive more than one file. Usually, though, we don't type each single item to be listed, but rather we use wildcards, then the shell will expand our shortcuts into a list of paths. There are wildcards, ranges and lists to be used.

Symbol Meaning Example
* Any set of characters (any length) *.fasta: all files ending with “.fasta”
? A single character A???.txt: files starting with A, followed by exactly 3 chars, endin by “.txt”
[a-z] Range: any single lowercase letters file1[a-c].txt: files called file1a, file1b and file1c, ending with “.txt”
[0-9] Range, any single digit reads_R[1-2].fastq: reads_R1.fastq and reads_R2.fastq
{a,b} Comma separated list of words photo_{andrea,john}.jpg: photo_andrea.jpg and photo_john.jpg

Menu

Clone this wiki locally