Summary of commands used

Password changing and logging out

Command Meaning
passwd change your UNIX password
exit end your UNIX session - i.e. logout

Command history

Command Meaning
history display a list of previously entered commands

Moving around the filesystem

Command Meaning
pwd print working directory ("where am I ?")
ls list files and directories (by default in the current working directory)
cd pathname change working directory to pathname where pathname is an absolute or relative path
cd .. move to the parent directory ("go up a level")
cd ../dir move to a directory contained in the parent ("go up and then down a level")
cd change working directory to the home directory ("take me home")
cd - return to the previous working directory

Listing files and directories

Command Meaning
ls list the contents of current working directory
ls pathname list the contents of the directory (or file) specified by pathname

ls option Meaning
-h display file sizes in human readable format
-S sort by file size
-t sort by modification time
-r reverses the sorting order
-R get a "recursive" listing i.e. list all files and directories below the current working directory (default) or a specified directory

Manipulating files

Copying commands

Command Meaning
cp file1 file2 copy the file file1 to another file file2
cp file1 dir copy the file file1 to the directory dir keeping the same filename
cp files dir copy the files listed in files (space-separated) to the directory dir keeping the same filenames
cp files . copy the files listed in files (space-separated) to the current working directory keeping the same filenames
cp file1 . copy the file file1 to the current working directory keeping the same filename
cp files dir copy the files listed in files (space-separated) to the current working directory keeping the same filenames
cp -r dir1 dir2 copy everything in directory dir1 (including itself) to directory dir2
cp -r dir1/* dir2 copy everything in directory dir1 (excluding itself) to directory dir2 i.e. make a complete copy of dir1

Moving commands

Command Meaning
mv file1 file2 move the file file1 to another file file2 i.e. rename file1
mv file1 dir move the file file1 to the directory dir keeping the same filename
mv files dir move the files listed in files (space-separated) to the directory dir keeping the same filenames
mv file1 . move the file file1 to the current working directory (.) keeping the same filename
mv dir1 dir2 rename dir1 to dir2 (same as moving everything in directory dir1 to directory dir2)

Removal (deletion) commands

Command Meaning
rm file1 remove the file file1
rm files remove the files listed in files (space-separated)
rmdir dir1 remove the directory dir1 - must be empty first
rm -r dir1 remove the directory dir1 and everything "below" it. Use with care !!

Wildcards

* matches zero or more characters
? matches a single character

Displaying files

Command Meaning
cat filename Display the contents of filename.
more filename Display the contents of filename a screenful at a time (scroll forward only).
less filename Display the contents of filename a screenful at a time (scroll forward or backwards).
head filename Display the first few lines of of filename.
tail filename Display the last few lines of of filename.
file filename Find out the likely file type of filename

more/less key Function
[space bar] or f scroll forward a screen
b scroll backward a screen
[down arrow] move forward one line
[up arrow] move backward one line
1G go to the first line
G go to the last line
NG go to line number N
[Ctrl-g] print current file position
q or [Ctrl-c] quit

Storage, permissions and file ZIPping

Command Meaning
df -vh show how much space is free on all filesystems
df -vh directory show how much space is free on the filesytem containing directory
df -vh ~ show how much space is free the on filesystem containing your home filestore
du -sh directory show how space is used by all files below directory
du -sh ~ show how much space has been used in your home filestore
echo $PATH show the search path
id show your group membership (identity)
chmod permissions_options file_or_directory change permissions on the file_or_directory (see below for an explanation of the options)
zip zip_file files create a ZIP file called zip_file from the list of files given in files (can contain wildcards)
unzip zip_file extract zip_file
unzip -l zip_file list the contents of zip_file without extracting it (useful for checking first)

chmod options

chmod commands have the general form:

chmod <applicability><action><permissions> file(s)_or_directory(s)

<applicability> contains one or more of these characters:

u applies only to the owner ("user")
g applies to members of the group
o applies to everyone outside the group ("others")

<action> consists of one of these symbols:

+ add permission(s)
- remove permission(s)
= set permission(s)

<permissions> contains one or more of these characters:

r read permission
w write permission
x execute permission

Xterm and nedit

Command Meaning
xterm & start an Xterm window in the background
nedit & start the nedit editor in the background

last updated on Thursday, 14-Sep-2017 14:38:49 BST by I.C. Smith