Linux/Unix Commands Quick reference

NAME

mv - move (rename) files  

SYNOPSIS

mv [OPTION]... SOURCE DEST
mv [OPTION]... SOURCE... DIRECTORY
mv [OPTION]... --target-directory=DIRECTORY SOURCE...

DESCRIPTION

Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.
Mandatory arguments to long options are mandatory for short options too.
--backup[=CONTROL]
make a backup of each existing destination file
-b
like --backup but does not accept an argument
-f, --force
do not prompt before overwriting equivalent to --reply=yes
-i, --interactive
prompt before overwrite equivalent to --reply=query
--reply={yes,no,query}
specify how to handle the prompt about an existing destination file
--strip-trailing-slashes remove any trailing slashes from each SOURCE
argument
-S, --suffix=SUFFIX
override the usual backup suffix
--target-directory=DIRECTORY
move all SOURCE arguments into DIRECTORY
-u, --update
move only when the SOURCE file is newer than the destination file or when the destination file is missing
-v, --verbose
explain what is being done
--help
display this help and exit
--version
output version information and exit
The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX. The version control method may be selected via the --backup option or through the VERSION_CONTROL environment variable. Here are the values:
none, off
never make backups (even if --backup is given)
numbered, t
make numbered backups
existing, nil
numbered if numbered backups exist, simple otherwise
simple, never
always make simple backups
Examples:
The "mv" command is commonly used for renaming a file and/or moving a file to another directory (folder).
To rename the file "titles.txt" in the current directory to "music_collection.txt" you would type
 mv titles.txt music_collection.txt 
To move the file "students.txt" from the current directory to the directory "/school" you can enter
 mv students.txt school/. 
The "." at the end means: place here without renaming. If you want to move and rename a file a file at the same time you would type:
 mv students.txt school/2nd_grade.txt 

1. Rename a File

While renaming a file using mv command, it keeps the inode number same even after moving it to a different name. If you move the file to a different filesystem, the inode number will be different.
$ cd /tmp    
$ ls -i sample.txt  136407 sample.txt    
$ mv sample.txt sample1.txt    
$ ls -i sample1.txt  136407 sample1.txt  

2. Rename a Directory

Just like renaming a file, you can rename a directory using mv command as shown below. This also keeps the inode number of the directory same after renaming.
If you just do ls -l dir, it will display the files in the directory. To display the directory properties, use -d option. -i option displays the inode number of the directory.
$ ls -ldi dir1  271365 drwxr-xr-x 2 bala bala 4096 2010-10-30 20:25 dir1    
$ mv dir1 dir2    
$ ls -ldi dir2  271365 drwxr-xr-x 2 bala bala 4096 2010-10-30 20:25 dir2  

3. Prompt for a Confirmation Before Overwriting

By default mv command will not ask for any confirmation if the destination file exist, it simply overwrites it. To avoid this you might want to get a confirmation from move command before overwriting the destination file using -i option as shown below. You may type either ‘y’ or ‘n’ to accept or reject the move operation.
$ mv -i sample.txt sample1.txt  mv: overwrite `sample1.txt'?  
$ mv -i sample.txt sample1.txt  mv: try to overwrite `sample1.txt', overriding mode 0644 (rw-r--r--)? y

4. Move Multiple Files to a Specific Directory

You can move multiple files using mv command. The following example moves the content of the current directory to a different directory.
$ cd chap1    
$ ls -F  ex1.c    ex2.c    ex3.c    example/   exercise/      
$ mv * chap2/  

5. Take a Backup of Destination Before Overwriting

Using mv –suffix option, you can take the backup of the destination file before overwriting. The original destination file will be moved with the extension specified in the -S or –suffix option.
$ ls  file1    file2    
$ mv --suffix=.bak file1 file2    
$ ls  file2    file2.bak  

6. Move only the files that don’t exist in the destination directory

When you do mv *, it will move all the files to the destination directory. However, if you want to move only the files from the source directory that don’t exist in the destination directory, use the mv -u option as shown below.
The following command will move only the ex2 and ex2 from chap1 to chap2, as ex1 file already existing in chap2, which will not be moved.
$ ls chap1  ex1    ex2    ex3    
$ ls chap2  ex1    
$ mv -u chap1/* chap2/    
$ ls chap1  ex1    
$ ls chap2  ex1    ex2    ex3  

About ls
Lists the contents of a directory.
Syntax
ls [-a] [-A] [-b] [-c] [-C] [-d] [-f] [-F] [-g] [-i] [-l] [-L] [-m] [-o] [-p] [-q] [-r] [-R] [-s] [-t] [-u] [-x] [pathnames]
-a Shows you all files, even files that are hidden (these files begin with a dot.)
-A List all files including the hidden files. However, does not display the working directory (.) or the parent directory (..).
-b Force printing of non-printable characters to be in octal \ddd notation.
-c Use time of last modification of the i-node (file created, mode changed, and so forth) for sorting (-t) or printing (-l or -n).
-C Multi-column output with entries sorted down the columns. Generally this is the default option.
-d If an argument is a directory it only lists its name not its contents.
-f Force each argument to be interpreted as a directory and list the name found in each slot. This option turns off -l, -t, -s, and -r, and turns on -a; the order is the order in which entries appear in the directory.
-F Mark directories with a trailing slash (/), doors with a trailing greater-than sign (>), executable files with a trailing asterisk (*), FIFOs with a trailing vertical bar (|), symbolic links with a trailing at-sign (@), and AF_Unix address family sockets with a trailing equals sign (=).
-g Same as -l except the owner is not printed.
-i For each file, print the i-node number in the first column of the report.
-l Shows you huge amounts of information (permissions, owners, size, and when last modified.)
-L If an argument is a symbolic link, list the file or directory the link references rather than the link itself.
-m Stream output format; files are listed across the page, separated by commas.
-n The same as -l, except that the owner's UID and group's GID numbers are printed, rather than the associated character strings.
-o The same as -l, except that the group is not printed.
-p Displays a slash ( / ) in front of all directories.
-q Force printing of non-printable characters in file names as the character question mark (?).
-r Reverses the order of how the files are displayed.
-R Includes the contents of subdirectories.
-s Give size in blocks, including indirect blocks, for each entry.
-t Shows you the files in modification time.
-u Use time of last access instead of last modification for sorting (with the -t option) or printing (with the -l option).
-x Displays files in columns.
-1 Print one entry per line of output.
pathnames File or directory to list.
Examples
ls -l
In the above example this command would list each of the files in the current directory and the files permissions, the size of the file, date of the last modification, and the file name or directory. Below is additional information about each of the fields this command lists.
Permissions Directories Group Size Date Directory or file
drwx------ 2 users 4096 Nov 2 19:51 mail/
drwxr-s--- 35 www 32768 Jan 20 22:39 public_html/
-rw------- 1 users 3 Nov 25 02:58 test.txt
Below is a brief description of each of the above categories shown when using the ls -l command.
Permissions - The permissions of the directory or file.
Directories - The amount of links or directories within the directory. The default amount of directories is going to always be 2 because of the . and .. directories.
Group - The group assigned to the file or directory
Size - Size of the file or directory.
Date - Date of last modification.
Directory of file - The name of the file or file.
ls -laxo
Our favorite ls command, which lists files with permissions, shows hidden files, displays in a column format, and doesn't show the group.
ls -1 | wc -l
Count how many files and directories are in the current directory. To prevent any confusion, the above command reads ls <dash><the #1> <pipe> ls <dash><the letter l>. This command uses the ls command to list files in a bare format and pipes the output into the wc command to count how many files are listed. When done properly, the terminal should return a single number indicating how many lines were counted and then return you to the prompt.
Tip: Keep in mind that this is also counting the ./ and ../ directories.
ls ~
List the contents of your home directory by adding a tilde after the ls command.
ls /
List the contents of your root directory.
ls ../
List the contents of the parent directory.
ls */
List the contents of all sub directories.
ls -d */
Only list the directories in the current directory.

About cp
Copies files from one location to another.
Syntax
cp [OPTION]... SOURCE DEST
cp [OPTION]... SOURCE... DIRECTORY
cp [OPTION]... --target-directory=DIRECTORY SOURCE...
-a, --archive same as -dpR
--backup[=CONTROL] make a backup of each existing destination file
-b like --backup but does not accept an argument
--copy-contents copy contents of special files when recursive
-d same as --no-dereference --preserve=link
--no-dereference never follow symbolic links
-f, --force if an existing destination file cannot be opened, remove it and try again
-i, --interactive prompt before overwrite
-H follow command-line symbolic links
-l, --link link files instead of copying
-L, --dereference always follow symbolic links
-p same as --preserve=mode,ownership,timestamps
--preserve[=ATTR_LIST] preserve the specified attributes (default: mode,ownership,timestamps), if possible additional attributes: links,
all
--no-preserve=ATTR_LIST don't preserve the specified attributes
--parents append source path to DIRECTORY
-P same as '--no-dereference'
-R, -r, --recursive copy directories recursively
--remove-destination remove each existing destination file before attempting to open it (contrast with --force)
--reply={yes,no,query} specify how to handle the prompt about an existing destination file
--sparse=WHEN control creation of sparse files
--strip-trailing-slashes remove any trailing slashes from each SOURCE argument
-s, --symbolic-link make symbolic links instead of copying
-S, --suffix=SUFFIX override the usual backup suffix
--target-directory=DIRECTORY move all SOURCE arguments into DIRECTORY
-u, --update copy only when the SOURCE file is newer than the destination file or when the destination file is missing
-v, --verbose explain what is being done
-x, --one-file-system stay on this file system
Examples
cp file1.txt newdir
Copies the file1.txt in the current directory to the newdir directory.
cp /home/public_html/mylog.txt /home/public_html/backup/mylog.bak
Copies the mylog.txt file in the public_html directory into the public_html/backup directory as mylog.bak. The files are identical however have different names.
cp *.txt newdir
Copy all files ending in .txt into the newdir directory.
cp -r /home/hope/files/* /home/hope/backup
Copies all the files, directories, and subdirectories in the files directory into the backup directory.
yes | cp /home/hope/files/* /home/hope/files2
Copies all the files and subdirectories in files into the files2 directory. If files with the same name exist or it's prompted to overwrite the file it answers yes.
Additional information
Many new versions of Linux/Unix or their variants may also be able to use copy in place of cp or have an alias setup for cp as copy.

About rm
Deletes a file without confirmation (by default).
Syntax
rm [-f] [-i] [-R] [-r] [filenames | directory]
-f Remove all files (whether write-protected or not) in a directory without prompting the user. In a write-protected directory, however, files are never removed (whatever their permissions are), but no messages are displayed. If the removal of a write-protected directory is attempted, this option will not suppress an error message.
-i Interactive. With this option, rm prompts for confirmation before removing any files. It over- rides the -f option and remains in effect even if the standard input is not a terminal.
-R Same as -r option.
-r Recursively remove directories and subdirectories in the argument list. The directory will be emptied of files and removed. The user is normally prompted for removal of any write-protected files which the directory contains. The write-protected files are removed without prompting, however, if the -f option is used, or if the standard input is not a terminal and the -i option is not used.  Symbolic links that are encountered with this option will not be traversed.  If the removal of a non-empty, write-protected directory is attempted, the utility will always fail (even if the -f option is used), resulting in an error message.
filenames A path of a filename to be removed.
Examples
rm myfile.txt
Remove the file myfile.txt without prompting the user.
rm -rf directory
Remove a directory, even if files existed in that directory.
About rmdir
Deletes a directory.
Syntax
rmdir [OPTION]... DIRECTORY...
--ignore-fail-on-non-empty ignore each failure that is solely because a directory is non-empty.
-p, --parents Remove DIRECTORY and its ancestors. E.g., `rmdir -p a/b/c' is similar to `rmdir a/b/c a/b a'.
-v, --verbose output a diagnostic for every directory processed.
--version output version information and exit.
Examples
rmdir mydir

cal = Calendar.
Prints a calendar for [[month] year].
cat = Catenate.
Joins files end to end or send file to standard output.
  • -n = Numbers all lines as they are written to std. output.
  • -E = Ends of lines are marked with dollar signs.
  • -s = Squeeze so that there is never more than one blank line in a row.
  • -v = Show non-printing characters (control as ^M and alt as M-).
  • -t = Tabs are marked with ^I.
cd = Change Directory.
".." is one directory up. Without a path, sends you home.
chgrp = Change Group.
Changes the group associated with file-list. Group is the name or group ID of new group.
Syntax: chgrp [options] group file_list
  • -c = Changes. List only those files whose group ownership changes.
  • -R = Recursive. When directory is listed, changes all files within it.
  • -v = Verbose. List all files and whether changed ownership or not.
chmod = Change Mode.
Changes how a file can be accessed.
Syntax: chmod [options] who operation permission file-list
  • who: u=user, g=group, o=other, a=all (can use in place of ugo).
  • operation: "+"=adds permission, "-"=removes permission, "="=sets permissions specified user, resets permissions for that user class.
  • permission: r=read, w=write, x=execute, t=sets sticky bit, s=sets user or group ID when executed.
  • -c = Changes. Display list of files that have their permissions changed.
  • -R = Recursive. Descends directory and sets all files to those specified.
  • -v = Verbose. Describes whole operation.
Using the number method:
Read=4, Write=2, Execute=1
Order is user, group, other.
Ex: chmod 755 /home/mydir/myfile
chown = Change Owner.
Options available are -c, -R, and -v and above.
Syntax: chgown [options] owner file_list
cmp = Compare.
Unlike diff, also compares binary files. Exit status=0 if same; status=1 if different. If file2 is omitted, uses standard input.
Syntax: cmp [options] file1 [file2]
  • -i n = Skips first n bytes in each file.
  • -c Characters. Shows bytes where files first differ.
  • -s Silent. Suppress output.
  • -l Long/verbose. Show all bytes that differ.
comm = Compare two SORTED files.
Outputs 3 columns: Lines only in file1, lines found only in file2 and lines common to both. Use a hyphen for file1 or file2 to read standard input.
Syntax: comm [opt] file1 file2
  • -1 = Do not display column1.
  • -2 = Do not display column2.
  • -3 = Do not display column3.
cp = Copy.
Shorthand for working directory is "."
Syntax: cp source-file destination-file.
  • -b = Backup. If overwriting a file, makes a backup copy, same name with tilde (~) appended.
  • -i = Interactive. Prompts if overwriting a file.
  • -p = Preserve. Preserves the owner, group and permissions when copying.
  • -r = Recursive. Can use if destination is a directory. If any files in source list are a directory, will copy whole directory structure.
date = Date.
Displays the time and date. Superuser can specify newdate as nnddhhmm[cc[yy]] where nn=month, dd=day, hh=24 hour, mm=minute, cc=1st 2 year digits, yy=last 2 year digits. Use help option for format.
Syntax: date [opt] [+format] OR date [opt] newdate
  • -u = Universal. Sets date in Greenwich Mean Time and is converted by date utility.
  • --help = How to use date and list of field descriptors.
df = Disk Free.
Reports on free space in blocks left on any mounted device. Usually 1kb (1024 bytes) per block. Without an argument, reports on each mounted device.
Syntax: df [opt] [file_list]
  • -h = Human Readable sizes (KB, MB, GB)
  • -F "type" = One of file system types listed in /etc/vfstab
  • -t = Lists free AND allocated space (see "du")
  • -i = Report on inodes instead of blocks
diff = Difference.
Displays the difference between two files on a line-by-line basis. If a hyphen is used for either file, diff uses standard input. Output is line number that is different, file1 differences are marked with "<" and file2 differences are marked with ">", a=add, d=delete, c=change. If file is too big, use bdiff.
Syntax: diff [options] file1 file2
  • -b = blanks. Ignore differences in blanks, tabs and spaces.
  • -q = quick?. No detail, only reports if files differ
  • -c [or -C lines]. Context. Lists lines surrounding the differences for context (default=3)
  • -i = ignore. Ignore differences in case when comparing files
  • -e = editor. Creates a script for "ed" editor to make file1 into file2 (may not work)
du = Disk Usage.
With no options does current directory.
Syntax: du [options] [file-list]
  • -h = Human-Readable units used instead of bytes
  • -a = all. Space used by all files, not just directories
  • --s = summary. Only the totals for each directory
  • -s = silent. Display only totals
echo = Echo
Echos argument, followed by new line, to standard output.
The shell recognizes wildcards in the message.
Syntax: echo [options] message
  • -n = Suppresses the newline terminating the message
  • --help = Get help using echo
    • Escape Characters:
    • \a = bell
    • \c = suppress newline at end
    • \n = newline
    • \t = horizontal tab
    • \v = vertical tab
    • \\ = backslash
file = File
Classifies files according to their contents. Works by examining the beginning of a file...the results are not always correct! Uses /etc/magic to help determine file types.
Syntax: file [option] file_list
  • -f = File option will read list of files from a file instead of command line
  • -i = Ignores symbolic links
find = Find
Performs searches for files with many options (many not listed here). Searches current directory or all subdirectories in "path". A space separating criteria is logical AND; separate criteria with "-o" for a logical OR. Negate any criteria by preceding with a "!".
Syntax: find [path(s)] [expression]
  • -atime +/-n = Files accessed more or less than n days from now
  • -group group = Files belonging to a group or group ID
  • -inum n = File with a specific inode number n
  • -mtime +/-n = Files modified more or less than n days from now
  • -name filename = Searches to match the name of a file. Ambiguous references must be quoted
  • -newer filename = Files modified more recently than filename
  • -nogroup = Files belonging to a group not in /etc/group
  • -nouser = Files owned by users not in /etc/passwd file
  • -perm nnn = Files with permission mode=nnn
  • -size +/-nk = Files with size greater than or less than n kilobytes
  • -type filetype = Searches to match the following types
    • b = Block special file
    • c = Character special file
    • d = Directory file
    • f = Ordinary file
    • p = Fifo (named pipe)
    • l = Symbolic link
  • -user user = Files owned by a username or user ID
fmt = Format
Attempts to make all non-blank lines of a file nearly equal by moving the "newline" characters. Indentations and spaces between words aren't changed. Moves formatted version of files in file_list to standard output. Single option -n changes output to n characters. The default is 72.
Syntax: fmt [option] [file_list]
ftp = File Transfer Protocol.
Interactive client program for moving files between computers. Remote computer must be running the ftp service. You need an account or you can try "anonymous".
  • -i = interactive on/off. I need to use on my Web server not to get prompted with mput or mget (e.g., ftp -i machine_name)
  • -v = verbose.
  • FTP Commands
  • ascii = Sets transfer for plain-text files (usually the default)
  • bin[ary] = Sets transfer for binary files (pictures, MS Word, etc.)
  • bye = Closes connection to remote computer and ends ftp session
  • cd directory = Change Directory or takes you to remote home
  • delete filename = Deletes remote file
  • disc[connect] = Closes connection and ends ftp session
  • get file1 [file2] = Get file to the directory you started ftp. Can rename as file2
  • lcd = Local Change Directory (on starting machine)
  • ls = List command, as described below
  • mdelete = Deletes multiple files listed or described with wildcards
  • mget = Gets multiple files listed or described with wildcards
  • mkdir = Make Directory file on remote machine
  • mput = Puts multiple files listed or described with wildcards
  • open machine_name = Open a connection to a remote host
  • put file1 [file2] = Put file from local machine to remote machine (option to rename)
  • pwd = Print Working Directory (on remote machine)
Note on mget and mput: I've seen a bunch of searches for mget & mput "recursive" or "directory" and I haven't seen a command to do this. Try first using the "tar" command below to bundle the directories and then transfer the resulting file. If you use linux, gftp can be a big help. Just watch the format files are sent in (ascii/bin).
grep = Global Regular Expression Parser
Searches one of more files for a string or regular expression. Without options, sends matches to standard output. Using "*" for file list, searches all files in directory. Exit codes sent are 0=match, 1=no match, 2=error/not accessible.
Syntax: grep [options] pattern [file_list]
  • -c = count. Displays only the number of lines that have a match
  • -h = no header. For multiple files, leave out preceding file name
  • -i = ignore case.
  • -l = list. Display only the file names that have a match
  • -n = number. Precede each matching line with its line number
  • -q = quiet. Only send exit code
  • -s = suppress. Do not send error messages
  • -v = reverse. Will display all lines NOT matching the pattern
  • -w = word. Matches to a specific word and leaves out any other forms or longer words
gzip and gunzip = Zip and Unzip
Compresses and uncompresses one or more files. When using gzip, original file is deleted and new file has the extension ".gz". With recursive option, gzip will recursively compress subdirectories. Can also read from standard input. File attributes of owner and permission aren't changed. [tar -z = gzip]. Text files reduced 60%+.
Syntax: gzip [options] [file_list]
  • -d = decompress. The same as using gunzip.
  • -# = compression level. Substitute "#" with a number from 1 (fastest) to 9 (best). Default=6.
  • -f = force compression and don't give me any back-talk
  • -r = recursively descend directory tree to (de)compress
  • -c = sends results to standard output instead of overwriting file
  • -v = verbosely describe what was done
head
Displays the beginning of a file or standard input.
Syntax: head [options] [file_list]
  • -n = number of lines to display (I think 10 is the default?)
  • -q = quiet. Don't show header info. for multiple files
info = Information
Information utility developed by GNU project. Hypertext system on Linux shells, utilities and programs. Uses "node" to mean a screenful of stuff. n = next, p = previous, d = initial node. "C-h" for help is "Control-h".
kill
Terminates processes you own or are lord over. Sends software termination signal "15" by default. Use kill -9 if you REALLY want to kill process. You can use "ps" utility to get Process ID numbers. Superuser "kill -9 0" shuts down system.
Syntax: kill [options] PID_list
less
Text file pager like "more" utility but more powerful (less is more). Displays a command prompt after each screen of text.
Syntax: less [options] [file_list]
  • -i = ignore case. Searches for lower-case strings match both lower and upper case.
  • -m = reports the percentage of file viewed with each prompt
  • -N = line numbers are displayed
  • -s = suppresses multiple blank lines to a single line (while viewing)
  • -xn = sets tab stops "n" spaces apart (default=8)
  • -zn = sets scroll size to "n" lines (default is screen size)
  • less commands
  • [n]spacebar = scroll 1 page at a time
  • h = help is displayed (using less)
  • [n]return = jumps down by n lines at a time
  • [n]b = go back n lines
  • q = quit
ln = Link
Create a link (pointer) to a single file/inode number. You can also create a directory link to a file list using second syntax. A Windows shortcut is like "ln -s".
Syntax1: ln [options] file1 new_link
Syntax2: ln [options] file_list new_directory_link
  • -s = symbolic. An indirect link containing the pathname to a file. Can be a directory.
  • -i = interactive. Prompts you if "new_link" already exists
  • -f = force. Forces "new_link" to be overwritten if it exists
  • -b = backup. Works only with -f, makes a backup by adding "~" to file name
ls = List
Shows files and directories in current directory if one not named. The columns using the "long" option (-l) are: The type of file (e.g., d=directory, l=link, -=normal file); 3 sets of 3 permissions for the owner, group and others; the # of hard links to the file; name of the owner; name of the group file belongs to; size in bytes (use -h to get human readable sizes) for most files, but if a device then it shows major and minor device numbers; time last modified (-t sorts by time last modified); filename.
  • -a = all files (includes hidden files and directories)
  • -b = displays nonprinting escape sequences
  • -c = with -l, displays last time inode # was changes
  • -C = vertical columns; the default for terminal
  • -F = format: shows slash after directory,asterisk after files and @ after links
  • -l = long format (verbose)
  • -L = gives info on files referenced by links instead of links themselves
  • -o = no color
  • -r = reverse. lists filenames (or times) in reverse order
  • -R = recursively lists subdirectories.
  • -t = time. Sorts by time last modified
  • -u = with -l, displays last accessed time; with -t, sorts by time last accessed
  • -x = sorts files horizontally
  • -X = sorts files by their extensions
  • -1 = sorts in single column (default if not to terminal)
man = Manual (also xman)
Online documentation, sometimes outdated. Follow man with topic name or "man man" to learn about it. Sections include (1) user programs, (2) system calls, (3) library functions and subroutines, (4) special files (devices), (5) file formats, (6) games, (7) miscellaneous, (8) system administration, (9) kernel internal variables and functions. Note: Unless you include a manual section, man gives the earliest occurrence in the manual of the word. Ex: man 2 write looks in "system calls" for write.
mkdir = make directory
Syntax: mkdir [options] directory_list
  • -m = mode. Set the permissions to mode given (see chmod).
mv = Move
Effects of "cut and paste" or "rename". Using either relative or absolute path names
Syntax1: mv [options] old-file new-file
Syntax2: mv [options] old-file-list new-directory
  • -b = backup. Creates backup of files that would have been overwritten. Adds "~" to filename.
  • -f = force. Cause mv not to prompt. Need "write" permission in target directory.
  • -i = interactive. Prompts you if file will be overwritten.
  • -u = update. Causes mv to compare modification times of files if being overwritten and only replace with newer.
passwd = Password
Use to change your password at any time.
paste
Pastes corresponding lines of two files. Like cat but separated by a tab. Use ">" to put in a file.
Syntax: paste [options] file_list/std. input
  • -d = delimiter list. Can have a character between each item instead of a tab. If a list, the characters change with each spacing.
pine
Pine mail and news reader replaced by alpine: http://www.washington.edu/alpine/
ps = Process status
Displays info. on running processes, either all or ones you specify.
Syntax: ps [options] [process # list]
  • -a = all. Reports on all user processes
  • -f = family? Indents each child process and lists it after its parent
  • -h = header. Omits header information
  • -l = long. Shows more detailed info. about processes
  • -m = memory. Display memory size information in 1024-byte blocks
  • -u = username. Adds username, time started, %CPU, %MEM to display
  • -w = wide. Extends the display so it is wrapped vs. truncated
  • -x = extra? Includes processes not attached to terminals. Add to "a" to get true ALL
  • Process Status Display
  • COMMAND = Command line that started process (always last)
  • %CPU = Percent of CPU time process is using (approximate)
  • F = Flags associated with the status
  • %MEM = Percent of RAM that process is using
  • PID = Process Identification Number
  • PPID = Parent Process Identification Number
  • PRI = Priority
  • RSS = Resident Set Size (blocks of memory)
  • SIZE = Size (in blocks) of process core image
  • START = Time the process started
  • STAT = Status
    • D = Sleeping and cannot be interrupted
    • N = May have a reduced priority
    • R = Available for execution
    • S = Sleeping
    • T = Either stopped or being traced
    • Z = Zombie that is waiting for child to terminate
  • TIME = Elapsed time process has been running
  • TTY = Terminal name controlling process
  • UID = User ID of person who owns process
  • USER = Username of person who owns the process
  • WCHAN = If process is waiting, gives address of kernel function that caused wait
pwd = Print working directory
The name says it all. Use with "whoami" if you space out...
rm and rmdir = Remove
Remove a file/link or use rmdir to remove an empty directory.
Syntax: rm [options] file_list
  • -f = forced removal without back-talk
  • -i = interactive. Asks before removing each file
  • -r = recursive. Deletes contents of a directory, including all of its subdirectories. Be careful.
rpm = Redhat Package Manager.
Useful for installing precompiled software, managing updates, viewing info. on packages, etc. Works with most UNIX systems.
Syntax: rpm options rpm_file
  • -ivh = INSTALLATION of new package
  • -Uvh = UPDATE existing package (this also works with no previous package)
  • -Fvh = "Refresh" a package
  • -a = Query all packages
  • -c = List configuration files changed by package
  • -e = UNINSTALL existing package
  • -l = List all the FILES within a package
  • -q = Query package for its bio (raison d'ĂȘtre)
  • -qlp = Shows what files a package installs
  • -qip = Find out what a package does
su = Superuser/substitute user
Type "exit" to assume role of previous user.
tail
Displays the end of a file, the last 10 lines by default. Will display file names between files in file_list.
Syntax: tail [options] [file_list]
  • -f = follow. After copying last line, tail waits and copies additional lines from the file as it grows. Use kill to stop
  • -n = Show the last "n" lines of the file
  • +n = Show the end of the file, starting with line "n"
  • -q = quiet. Suppress header information between files
tar = Tape archive
Can create, add to, list and retrieve files from an archive file.
Syntax: tar option [modifiers] [file_list]
  • Options
  • -c = create. Stores the named file(s) in a new archive. If directory, works recursively
  • -r = append. Writes the file list to the end of an archive
  • -t = table of Contents. Without file_list, produces a table of contents of archive. Works with verbose option
  • -u = update. Adds the files to the archive if they are not already in the archive
  • -x = extract. Extracts the file list (or all files) from the archive.
  • --help = complete list of options.
  • Modifiers - If takes an argument, must be last.
  • -C directory= Changes working directory before processing
  • -f = Filename. Uses as the name of the archive
  • -h = Follow symbolic links and include the linked files
  • -P = Allows for absolute pathnames
  • -v = Verbose. Lists each file as tar reads or writes it
  • -Z = Uses utilities compress and uncompress when creating or extracting archive
  • -z = Uses the utilities gzip and gunzip (or uncompress) when creating or extracting archives
top
Dynamic version of ps. Constantly shows processes with most CPU usage.
  • -dn = Leave an "n" second display between new display. Default is 5 seconds.

Removes the directory mydir
rm -rf directory/
Remove a directory, even if files existed within that directory.

No comments:

Post a Comment