Chap4 - The Shell - File Management
Chap4 - The Shell - File Management
home public
For Example:
ls -l /dev/tty
crw-rw-rw- 1 root root 5, 0 2003-03-14 08:07 /dev/tty
ls -l monday.txt w1.c
-rw-r--r-- 1 someuser users 214 2006-01-23 14:20 monday.txt
-rw-r--r-- 1 someuser users 248 2005-10-12 13:36 w1.c
ls –ld uli101
drwxr-xr-x 2 someuser users 4096 2006-01-17 16:43 uli101
cd directorypath
○ Used to change to a directory. Entering the cd command without the directory path will
change to the user’s home directory.
Basic Commands
ls
rmdir directorypath
○ Used to remove only empty directories (i.e. directories that contain no subdirectories or
regular files). A user cannot remove a directory from within the directory location itself.
Basic Commands
mv sourcepath destinationpath
○ Used to move a file from one location to another and/or rename the file. The mv
command can be used to move directories as well as files. The –i option asks for
confirmation if the destination filename already exists.
cp sourcepath destinationpath
○ Used to copy a file from one location to another. The cp command can be used to backup
important files.
○ The –i option asks for confirmation if the destination filename already exists.
○ The -r option allows copying of directories and their contents
Basic Commands
rm filepath
○ Used to remove a regular file.
rm -r filepath
○ Used to recursively remove a directory and it's contents. Recursive means to descend to
lower levels, which in this case, indicates that subdirectories and it contents are also
removed.
Note: it is a good idea to include the –i option to confirm deletion of subdirectories and its
contents!
Basic Commands
cat filepath
➢ To join files (i.e. to concatenate files). For example, cat file1 file2 file3 will display the contents of file1 and file2
and file3 on the screen at the same time.
➢ To display the contents of small files (files longer than the screen will scroll to the end).
For example, issuing the command cat .bash_profile in your home directory would display the contents of your
setup file.
more filepath
➢ Used to display the contents of large regular files one screen at a time. The user can navigate
throughout the file by pressing keys such as:
➢ spacebar Move to next screen
b Move to previous screen
enter Move to next line
/car Search for pattern "car"
q Exit to shell
less filepath
➢ Works like more command, but contains more navigation features.
Basic Commands
touch path
file path
➢ finger username
○ Used to display additional information regarding the user (regardless whether or not the user is
currently logged onto the system).
➢ who
− Used to display a list of other users currently logged on to the same system is the user. Useful
options with the who command are –i and -T
Other Unix/Linux Commands
➢ passwd
○ Used to change an user's password on a standalone system. After issuing this
command, the system will prompt the user for their existing password – if that password
verifies, then the user is asked to enter and re-enter their new passwords.
○ While entering in the new password, feedback may be provided to reject unsuitable passwords
(see previous notes on how to create a valid password)
○ Please note that most of Seneca's systems rely on a centralized user directory, so the usage of
the passwd command here is limited
Other Unix/Linux Commands
➢ date
○ Used to display the current date and time of the server. The super-user (i.e. root-user) can use this
command to set the date and time. Refer to the online manual to format date display.
➢ cal
○ Used to display the current month’s calendar (by default). The user can also display the yearly
calendar (year as the first argument), or a specific month for a specific year (month number as the
first argument, and year as the second argument).
Getting Help with Commands
A comprehensive online manual for common UNIX/Linux commands exists on your server
Command Structure:
Options:
-k provides short (one-line) explanation relating
to the commands matching the character string. This
can be used if user doesn’t know name of command.
eg. man -k calendar
THANKS