Sei sulla pagina 1di 2

Information Technology File System Manipulation Move (Rename) Files and Directories

Rice University
July 11, 2002 mv present-filename new-filename to rename a file
Create (or Make) a Directory mv source-filename destination-directory to move a file into another
Document No. UNIX 1.01
directory
UNIX Reference Card mkdir directory-name create a directory called directory-name options: -i interactive mode. Must confirm file overwrites.

Anatomy of a Unix Command Look at a File Copy Files


more filename display file contents, same navigation as man
command-name -option(s) filename(s) or arguments cp source-filename destination-filename to copy a file into
head filename display first ten lines of a file another file
tail filename display last ten lines of a file
Example: wc -l sample cp source-filename destination-directory to copy a file into
another directory
options:
The first word of the command line is usually the command name. This options:
-# replace # with a number to specify how many lines to show
is followed by the options, if any, then the filenames, directory name, or -i interactive mode. Must confirm overwrites. Note: this
other arguments, if any, and then a RETURN. Options are usually pre- option is automatically used on all IT’s systems.
ceded by a dash and you may use more than one option per command. -R recursive delete
List Files and Directories
The examples on this reference card use bold case for command names
and options and italics for arguments and filenames. ls lists contents of current directory
Remove (Delete) Files and Directories
ls directory-name list contents of directory rm filename to remove a file rmdir directory-name to remove an
Important Note about UNIX Commands empty directory
options: options:
-a list all files including files that start with “.”
UNIX commands are case sensitive. Type commands exactly as shown; -i interactive mode. Prompt for confirmation. Note: this
-s list size of files (in kilobytes)
most UNIX commands are lower case. File and directory names can be is option is automatically set up on all IT’s systems.
-l long list, shows ownership, permissions, and links
lower, upper, or mixed case but must be typed exactly as listed. Com-
-l -g lists the group of each file or directory when used with -l
mands prefaced by a ^ (caret) mean to hold down the CONTROL key
-t list files chronologically
Change File Access Permissions
and then press the indicated character.
-F append “*” to executable file name, “/” to directory name, chmod [who op permission] filename
and “@” to symbolic link who can be any combination of:
On-line Documentation -u list files using time of last access instead of time of last u (user)
modification g (group)
man command display on-line manual pages about command o (other)
Navigation: SPACEBAR moves down 1 screen pwd (display the name of present working directory) a (all) (i.e. ugo)
RETURN move down 1 line
^d move down 1/2 screen Change Working Directory op adds or takes away permission, and can be:
^b move up 1/2 screen + (add permission),
q exit cd to change to your home directory
- (remove permission), or
h help cd directory-name to change to another directory = (set to exactly this permission)

examples:
Printing permission can be any combination of
cd test change to the directory named test r (read)
w (write)
lprloc lists available printers Directory Abbreviation x (execute)
setenv PRINTER printer set the default printer
pcpasswd initialize SAMBA password for lab ~ home directory (tilde) Ex: chmod a+x filename (makes filename executable by everyone)
printing /login; only works on Owlnet’s
~username another user’s home directory
short-earred and long-earred servers
http://www.owlnet.rice.edu/webprint.shtml . current or working directory Shell Tools
web-based printing; view current charges .. parent of working directory
lpr option filename print file Wild Cards
lpq option check status of print queue ? single character wild card
lprm option remove jobs from printer queue * arbitrary number of characters
options: -Pprinter specify a printer other than the default
History: Command Repetition Run Command in Background: Job Control Program Compilation
history display list of most recent commands To run a command in the background, as opposed to the more common
f90 filename.f FORTRAN compiler (also f77 code)
!! repeat the entire last command line at any point method of running commands in the foreground, append an & to the
cc filename.c C compiler
in the current command line end of a command string. Then, you can type more commands to the
gcc filename.C C compiler (other suffixes: .cc, .cxx, .cpp, .c++)
!$ repeat the last word of previous command command prompt, or even run more commands in the background for
g++ filename.c++ C++ compiler
line at any point in current command line simultaneous command execution.
pc filename.p Pascal compiler
!^ repeat first argument from previous command
line at any point in the current command line Control-Z stop (interrupt) foreground job
options:
!n repeat command line n jobs list of background jobs
!!:p display previous command bg run a stopped job in the background -o filename direct output of program to filename
-l library include library in program compilation
!string command beginning with string fg resume stopped job in the background
!* repeat all arguments to previous command
File Operations
Command I/O User Information and Helpful Commands
> command output redirection (create new) Search for Patterns in Files env lists your environment settings
>> command output redirection (append) who lists users on the local system
< command input redirection (from file) grep search-string filename [filename...] to find and type out lines con-
finger username@host.domain
<< command input (from script or standard input) taining the string in a file
looks up information on another user

Alias options: -v type out lines that don’t contain the string (invert the search)
clear clears screen
ntalk username@host.domain
alias alias-string command-string Counting Words in a File talk to another user
wc filename counts the number of words, lines, or characters in a file lprloc shows names and locations of printers
Alias abbreviates a command string with an alias string. For multi-
stty sane resets terminal characteristics to a
command strings, enclose commands in quotes. options: -w words
usable set
-l lines
stty display terminal characteristics
Example: alias shut chmod go-rwx -m characters
date displays current time and date
cal year for yearly calendar
To use the aliased command shut on a file, and turn off read, write, and Compare Files cal ## #### for monthly calendar
executable permissions for all users except yourself, type shut filename.
diff filename1 filename2 compares contents of filename1 and filename2 (month-year)
on a line-by-line basis ssh host.domain user interface to a remote system
Process Control
which command locate a command; display its pathname
File Transfer
Process Status spell filename report spelling errors
mail address sends mail to user at the specified address (using the for-
ispell filename interactive spell-checker
ps (display the status of the current processes) mat is user@host.domain). ^d terminates input and sends message.
options:
-a include processes owned by other users echo $path inspect your search path
ftp host.domain use file transfer protocol to connect to remote host
-g display all processes computer. Type ? for commands.
-u display user-oriented processes bc basic calculator (^d to exit)
-x include processes with no controlling terminals Compress Files du display the number of disk blocks used
-gx display all of your local processes
per directory or file
compress filename compress file and rename it filename.Z
kill id-number terminate a process owned by you du -s display your total disk usage
uncompress filename.Z decompress file and rename filename
The id-number (PID-Process ID) can be quota -v display your disk quota and usage
gzip filename compress file and rename it filename.gz
found by first using the ps command. gunzip filename.Z decompress file and rename filename