Unix Shell

Unix Command Line

One of the scariest things about using a Unix based system is learning the file architecture and running programs through the command line interface, especially if you’ve be brought up on Windows as many of have!

Well thankfully, we here at MESA sympathise and we have found a few resources  to help you out. A great series of introductory screencasts on the unix shell can be found here, and a list of the more common commands and their effect is compiled below.

Directories

/                              “root” directory
/usr                         directory usr (sub-directory of / “root” directory)
/usr/potato              potato is a subdirectory of /usr
.                              current directory
..                             parent directory to current directory

Navigating

pwd                         Show the “present working directory”, or current directory.
cd                            Change current directory to your HOME directory.
cd /usr/potato          Change current directory to potato
cd INIT                    Change current directory to INIT which is a sub-directory of the current directory.

Listing

ls                          list contents of a directory
ls -l                       list a directory in long (detailed) format
ls -a                      List the current directory including hidden files. Hidden files start with “.”
ls -F                      lists contents of directory with all sub-directories followed with a /

Permissions

chmod u=rwx file    Changes the permissions of file to be rwx for the user

You must be the owner of the file/directory or be root before you can do any of these things.

Moving

cp file1 file2             copies file1 and names the copy file2
mv file1 newname    move or rename a file
mv file1 ~/AAA/       move file1 into sub-directory AAA in your home directory.
rm file1                    remove or delete file1
mkdir dir1               create directory dir1
mkdir -p dirpath      create the directory dirpath, including all implied directories in the path.
rmdir dir1                remove an empty directory

Viewing

cat filename             Dump a file to the screen in ascii.
head filename          Show the first few lines of a file.
head -n filename      Show the first n lines of a file.
tail filename            Show the last few lines of a file.
tail -n filename        Show the last n lines of a file.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>