Working with File System
Create a File
touch file-name create 0 sized file
cat > file-name create file by default
vi file-name use vi editor
Display File Contents
cat file-name display contents of file-name
more file-name display contents per screenfull
less file-name display contents per screenfull
head file-name display first 10 lines of file-name
tail file-name display last 10 lines of file-name
List Files and Directories
ls list contents of directory
ls -l list files in long format
ls -a include "."(dot) files
Copy Files
cp src-file dest-file copy src-file to dest-file
cp src-file dest-dir copy a file into a directory
cp -R src-dir dest-dir copy one directory into another
cp-i src dest copy & prompt before overwriting
Remove File
rm file-name remove(delete) a file
rmdir dir remove an empty directory
rm -r dir remove directory & contents
rm -i file-name prompt before removing file
Make a Directory
mkdir directory-name make a directory
Move(Rename) Files & Directories
mv src-file dest-file rename src-file to dest-file
mv src-file dest-dir move file into a directory
mv src-dir dest-dir rename src-dir,or move,to dest-dir
mv -i src dest move & prompt before overwriting
Change Directory
cd return to login directory
cd dir change to directory dir
cd.. change to parent of directory
Changing Access Modes
chmod mode-setting file-name change access permissions
for file file-name
chmod -R mode-setting dir change access privileges
for all files in dir
Mode Settings
u user
g group
o other(public)
+ add permission
- remove permission
r read
w write
x execute
Example: chmod go +rwx foo.c adds read write execute
permissions for group &
other(public) on foo.c
Mode Setting
4 read(r)
2 write(w)
1 execute(x)
ugo user-group-other order of numerical
mode setting
Example: chmod 765 foo.c read,write,execute permission
for user, read & write permission
for group and read & execute
permission for other on foo.c
Find Path and Name of Directory
pwd display absolute path of
present directory
find .-type f -print search directory & subdirectories
and list all files
ff file-name searches dir. & subdir. for file-name
Compress Files
tar cf file.tar files create a tar file named file.tar
containing given list of files
tar xf file.tar extract files from file.tar
gzip file compresses file and renames
it file.gz
gzip -d file.gz uncompress file.gz back to 'file'
tar czf file.tar.gz files create tar file with gzip compression
tar xzf file.tar.gz uncompress and extract files
Directory Abbreviations
~ (tilde) home directory
~user-name user-name's home directory
. (dot) Present directory
.. Parent directory of present directory
../.. Parent of parent directory
Searching
grep string file-name show lines containing 'string'
in 'file-name'
grep -v string file-name show lines not containing 'string'
grep -i string file-name show lines containing 'string'
locate file-name find all instances of file
Redirection
command > file direct output of command to 'file'
instead of standard output(screen)
replacing contents of file
command >> file direct output of command to 'file'
append to current file content
command < file 'command' receives input from file
instead of standard input(keyboard)
cmd1 | cmd2 "pipe" output of cmd1 to input of cmd2
script file log everything displayed on terminal
to 'file'; end with exit
User Information
who list current users
whoami who you are logged in as
finger user display information about 'user'
id user display information about 'user'
passwd change your password
quota -v show your disk space quota
last yourusername lists your last logins
System Information
df show disk usage
du show directory space usage
uname -a show kernel information
free show memory and swap usage
whereis app show location of 'app'
top show all running processes
date show current date and time
uptime show uptime since bootup
Process and Job Management
ps show active processes and
pid(process id) numbers
ps gx include "hidden" processes
jobs show current jobs and job id numbers
kill pid# kill process id 'pid'
killall proc kill all prcesses name 'proc*'
bg list bacground jobs
fg bring most recent job to foreground
fg %job-id# bring job 'job-id' to foreground
Information
man command-name show online manual pages
man -k string list one line summaries of man
pages containing 'string'
|