Tutorials - Linux Commands and File Structure

Linux Commands and File Structure

When a user logs in on a Linux or other UNIX-like system on the command line, they start in their home directory:

In that directory they will have the necessary privileges to create new folders, files and edit existing ones. There are a set of basic commands which every Linux command-line user must know. All commands come with options expressed as:
[command] -[option[s]]

Wildcard characters can be used to substitute for any other characters in a string. The asterisk (*) substitutes as a wildcard character for any zero or more characters, and the question mark (?) usually substitutes as a wildcard character for any one character.

Basic Linux Commands

ls (list):
Lists contents for particular directory, the current directory by default.

ls -ltr
List with long format, including file permissions, reverse order, by modification time

pwd (Print working directory):
Prints the directory where you're currently in.

mkdir (make directory):
Create new directory to hold files or subdirectories, if they do not already exist.

Example: mkdir fish Creates a directory called 'fish'.

cd (change directory): Change working directory from directory to another.

cd fish
Change to the directory 'fish' if it is a subdirectory of the current directory, or use cd /path/to/fish

cd ~
Returns to the /home/[username] directory. Very handy when you're lost!

rmdir (remove directory):
Remove empty directory. If there are files or directories existing under the directory, rmdir will fail.

Example: rmdir fish
Removes the directory 'fish' if it is a subdirectory and there are no files in it.

Makes a copy of file or directory from one place to another; normally followed by two arguments, one is the source file/directory, and the other is target file/directory.

Example:cp fishdata.txt fish/
Copies fishdata.txt in the current directory to the subdirectory 'fish'

mv (move):
Moves files or directories from one place to another, this has the effect of moving rather than copying the file. It can also be used to rename a file, by moving the file to the same directory, but giving it different name.

Example:mv fishdata.txt fish/eeldata.txt
Renames and moves to a new directory.

Deletes files from the system. It can be used to remove the directory no matter it is empty or not.

Example:rm fish/eeldata.txt
Removes the file eeldata from the subdirectory fish. To remove the entire subdirectory use - with caution! - the options rf, e.g., rm -rf fish/.

find (find) Finds a file in the directory tree starting at the given pathname according to name, type, size etc., depending on the options stated.

Example:find fish/ -name "*.txt"
Finds and displays all files with the "*.txt" in the subdirectory /fish and all over subdirectories of /fish.

grep (Originally "global search for regular expression and print" g/re/p in the editor ed). Searches and prints specified text from a list of files or standard input.

Example:grep eel fish/*
Finds and prints lines that contain the string 'eel' in the subdirectory fish/.

ps (Process Status):
Gives a snapshot of running processes. Useful to check the load status of the current system, cpu and memory use.

Example: ps -e
Lists all current processes

man [command] (manual):
The man command provides online access to the system's reference pages. It displays the reference pages for the commands and also system calls.

This is only the most basic listing of Linux commands. An excellent beginner's tutorial is available through Surrey University:

File system

Once one knows how to log on to a Linux supercomputer, how to move files to and from a directory and use basic commands, it is important to have a general idea of the layout of a Linux system. This is called the Filesystem Hierarchy Standard (FHS) defines the main directories and their contents in most Linux-based computer operating systems. Whilst a user will have most of their activity in the /home/username directory, it is handy to have a general list where everything is, at least from a top-level perspective. It's easy to get lost!

Directory Description
/ Root directory of the entire file system.
/bin/ Essential command binaries for all users.
/boot/ Boot loader files.
/dev/ Devices
/etc/ Host-specific system-wide configuration files
/home/ Users' home directories and personal settings
/lib/ Libraries essential for the binaries in /bin/ and /sbin/
/media/ Mount points for removable media such as CD-ROMs
/mnt/ Temporarily mounted filesystems (e.g., for dual boot systems)
/opt/ Optional application software packages
/proc/ Virtual filesystem documenting kernel and process status as text files
/root/ Home directory for the root user
/sbin/ Essential system binaries (e.g., init, route, ifup)
/srv/ Site-specific data which is served by the system
/tmp/ Temporary files (see also /var/tmp)
/usr/ Secondary hierarchy for user data; contains the majority of utilities, applications, libraries and the like
/var/ Variable files, such as logs, spool files, and temporary e-mail files

Top of Page