Jurgen—Some basic Unix commands

Some basic Unix commands

Definitions

{arg} – required parameter

[arg] – optional parameter

path – a filename which may include the path to the file, i.e.:

file

subdir/file

../parentsubdir/file

/from/root/dir/file

cmd1; cmd2 – execute two commands, one after the other

cmd1 | cmd2 – use the output of cmd1 as the input of cmd2 (pipe)

cmd > path – save the output of cmd in a file

Commands

ls – list files in current dir

ls -a – list all files (including hidden files)

ls -l – list files in long format

ls [path] – list files at directory path, i.e. ls /usr/bin

cd [path] – change working directory to path

pwd – print current working directory

date – print current date

mkdir {path} – make a directory

rm {path} – delete a file

rmdir {path} – delete a directory

mv {spath} {dpath} – move or rename file at spath to dpath

mv {spath} [spath, …] {dpath} – move several files to dpath (where dpath must be an existing directory)

cat {path} – print contents of file

grep text [path] – print lines containing text in file (or if no file, standard input)

less {path} – display contents of file with navigation

wc [path] – count characters, words, and lines in file (or use “wc -l” for lines only)

head [path] – print first 10 lines of file (or “head -30” to print first 30 lines)

tail [path] – print last 10 lines of file

ps -ef – list all processes on system

Examples

Note that the following are two different ways of doing the same thing:

grep bailux /etc/passwd

cat /etc/passwd | grep bailux

Make a subdirectory called ‘pictures’ and move all files ending in ‘.jpg’ there:

mkdir pictures

mv *.jpg pictures

How many processes does user ‘bailux’ have executing?

ps -ef | grep bailux | wc -l