Working with directories

This and next pages will list commands needed to copy, move, see contents, edit and delete files (and directories). Note that a directory is a type of file that contains information about its contents, which may be a mixture of other directories (subdirectories) and ordinary files. The "pwd" command prints the full name or the full path of current/working directory.

The "ls" command prints directory contents. Most of the commands take different options and arguments. For example, we saw that "cp" command needs two arguments. "ls" command can be used with many options and has one optional argument. If you ssh to the cluster where you have account and issue "ls -a" command, you should see several files listed, most of the names starting with a dot. Now try issuing "ls" command without any options. You may not see any files at all. The "-a" option tells "ls" to display hidden files - those files, whose name start with a dot. There are several ways to find information about options and arguments for a specific command. Many commands and programs have "--help" option to list help information about command. "ls --help" command will list help information about "ls" command.

You can also use "man" command to see manual page for a specific command. E.g., issue "man ls" to read about "ls" command. The "man" command will list only one page of the manual at a time. To navigate between pages you PgDn, PgUp and arrow keys. Alternatively you can use Space, B and Enter keys.

By default, right after ssh-ing to a Linux machine you would find yourself in your home directory, usually /home/<username>. Issue again the "ls -a" command. The first two directories in the list should be "." and "..". Every directory on a Linux machine will have those two directories. The "." directory means current directory and the ".." directory means parent directory, e.g. the directory one level up, that contains the current directory. For example, for /home/abc directory "." will mean /home/abc and the ".." will mean /home. With no arguments "ls" command prints contents of the current directory. To see contents of the parent directory, issue "ls ..". You should see a list of users on the system. You may guess that "ls ." command will provide same output as the "ls" command. To see contents of the root directory, issue "ls /".

To create new directory use "mkdir" command. For example, to create directory TMP in the current directory issue either "mkdir TMP" or "mkdir ./TMP". It's a good practice to organize files by creating directories and putting files inside of them instead of having all files in one directory. Try to avoid using spaces and other special characters (except "_") in the file names on Linux machines. While almost any character can be used in a file name, it's more complicated to refer to such names in CLI commands. Now, that you've created directory TMP in the current directory, what output do you think you will get if you issue "ls -a TMP" command? Check yourself.

In a graphical desktop environment to go to a different directory (folder), you would just click on the directory name. In the CLI you will use "cd" command (which stands for "change directory"). To go to the newly created TMP directory, issue "cd TMP". Issue "pwd" to verify that you're now in the new directory. "cd .." command should take you one level up. "cd /" will change current directory to root directory, while "cd" with no arguments will take you to your home directory.