Sie sind auf Seite 1von 8

Unix Commands

1. ls --- lists your files


ls -l --- lists your files in 'long format”

ls -a --- lists all files, including the ones whose filenames begin in a dot

2. mv oldname newname --- moves a file(mv command can be used to


change the name of a file)

3. cp filename1 filename2 --- copies a file

4. rm filename --- removes a file. It is wise to use the option rm -i, which will ask you for
confirmation before actually deleting anything
5. diff filename1 filename2 --- compares files, and shows where they differ

6. chmod options filename --- lets you change the read, write, and execute
permissions on your files. For example, chmod o+r filename will make the
file readable for everyone, and chmod o-r filename will make it unreadable
for others again

7. gzip filename --- compresses files, Gzip produces files with the ending '.gz'
appended to the original filename.

8. gunzip filename --- uncompresses files compressed by gzip.


9. gzcat filename --- lets you look at a gzipped file without actually having to gunzip it
(same as gunzip -c) (ex: gzcat filename | lpr)

10. tar

Use create compressed archives of directories and files, and also to extract directories and
files from an archive. Example:

% tar -tvzf foo.tar.gz

displays the file names in the compressed archive foo.tar.gz while

% tar -xvzf foo.tar.gz

ncftp

Use ncftp for anonymous ftp --- that means you don't have to have a password.

% ncftp ftp.fubar.net
Connected to ftp.fubar.net
> get jokes.txt

The file jokes.txt is downloaded from the machine ftp.fubar.net.

rsh

Use this command if you want to work on a computer different from the one you are
currently working on. One reason to do this is that the remote machine might be faster.
For example, the command

% rsh solitude

connects you to the machine solitude.

more

More is a command used to read text files. For example, we could do this:

% more poems

The effect of this to let you read the file "poems ". It probably will not fit in one screen,
so you need to know how to "turn pages". Here are the basic commands:

• q --- quit more


• spacebar --- read next page
• return key --- read next line
• b --- go back one page

head /Tail

Use this command to look at the head of a file

% head -n 20 essay.001

This displays the first 20 lines of the file.

% tail -n 20 essay.001

This displays the last 20 lines of the file.

11. wc - print the number of newlines, words, and bytes in files


Syntax: wc [OPTION]... [FILE]...

-c, --bytes

print the byte counts


-m, --chars
print the character counts
-l, --lines
print the newline counts
-L, --max-line-length
print the length of the longest line
-w, --words
print the word counts
--help
display this help and exit
--version
output version information and exit

printing

12. lpr filename --- print. Use the -P option to specify the printer name if you want to use a
printer other than your default printer. For example, if you want to print double-sided, use
'lpr -Pvalkyr-d
13. lpq --- check out the printer queue, e.g. to get the number needed for removal, or to see
how many other files will be printed before yours will come out

14. lprm jobnumber --- remove something from the printer queue. You can find the job
number by using lpq. Theoretically you also have to specify a printer name, but this isn't
necessary as long as you use your default printer in the department.
15. genscript --- converts plain text files into postscript for printing, and gives you some
options for formatting. Consider making an alias like alias ecop 'genscript -2 -r \!* | lpr
-h -Pvalkyr' to print two pages on one piece of paper.

16. nice: Run a command with modified priority


usage: nice -n[value] [command]
options: -nn--sets priority to n--value may range from 1 to 19 with 1 being highest
priority and 10 the default
example: nice -n 1 mysort -- run the mysort program at the highest priority

17. touch: Change file access and modification times


usage: touch [options] files - creates a blank file, or updates existing file
options: -c do not create file if it does not exist | -t use time specified
example: touch new.txt creates file new.txt
example: touch -c new.txt--updates new.txt node information to current
time but does not create new.txt
18. tee: Reproduces stdout in a file so that all the commands you enter and what
is displayed as responses are logged
usage: tee [options][file]
options: -a append to output file file
example: tee 6.21-log--begin logging what you enter into the file 6.21-log

19. tar: "Tape Archiver"; bundles a collection of files into one unit ("tarfile") for
archiving or transmitting
usage: tar [options][tarfile][files]
options: see manpage
example: tar cf - . | gzip -c > test.tar.gz--bundles everything in the current
directory, compresses it with gzip, creating a file called test.tar.gz
example: tar xvf files.tar--extracts files fromfiles.tar

20. ping: Sends packets to a network host


usage: ping [host] [timeout] (default for timeout is 20 seconds)
options: timeout period in seconds
example: ping 123.123.123.123 5--ping this IP address but give up after 5
seconds

21. passwd: Change password


usage: passwd - brings up dialogue that allows you to change your password
options: see manpage

22. mv: Move file under a directory structure or to new file name; original
(source) file will be gone
usage: mv [file] [dir]--moves file under existing directory dir
options: -f force copy over any existing file by that name | -i prompts user to
copy over files
example: mv temp.txt dir/ --moves temp.txt into directory dir/
example: mv -f temp.txt dir/ --moves temp.txt into directory dir/ erasing old
temp.txt if it exists
example: mv -i temp.txt dir/ --moves temp.txt into directory dir/ but asking
before overwriting old temp.txt if it exists

usage: mv [file1] [file2]--moves file1 to file2


example: mv temp.txt temp2.txt--renames temp.txt to temp2.txt
example: mv -f temp.txt temp2.txt--renames temp.txt erasing old temp2.txt
if it exists

23. more / less / pg: Display file


usage: more [file] - displays the contents of a file in ASCII; use spacebar to
advance by page, Enter to advance by line
options: -c clear before displaying | -d display error messages | "h" gives
help | "b" back
example: more -c temp.txt--clears display then prints contents of file
temp.txt

24. lpstat: Gives status of print jobs generated via the lp command
usage: lpstat [options]
options: see manpage
example: lpstat -pnohole--gives printer status of nohole print queue

25. history: Displays a chronologic list of the last n commands you've entered
usage: history to display history
usage: !! to recall last command (can be used for re-execution of command)
options: see manpage
example: set history=100--to save a stack of 100 commands

26. grep: Search for a pattern in file or files


usage: grep
options: -b precede each line by the line number | -c count number of times
found | -i ignore case of letters | -l print only names of files with line#s | -n
print line# with line of text | -x match full lines
example: grep -c alias .cshrc--counts the number of aliases in .cshrc
example: grep -b alias .cshrc--shows where the aliases are in .cshrc
example: grep -l main *--print names of files in current directory containing
main

27. find: Find files that match certain criteria


usage: find [criteria] [options] [files]
options: see "info find"
example: find $HOME -name '#*'--find all files with names beginning with
pound sign

28. du: Disk Usage summary by file or directory structure


usage: du [options][files]
options: -a make an entry for each file | -s display grand total only
example: du -s--prints summary for current directory; also see ezquota

29. chmod: Change access mode (permissions) of a file or directory


usage: chmod [options][files]
options: -f suppress error reporting | -R changes permission recursively--to
all subdirectories
example: chmod 777 -R public_html--changes permissions of everything in
public_html to read write and execute for everyone
example: chmod -777 temp--removes all permissions of file temp
example: chmod a+x temp--gives All users of file temp execute access
example: chmod go-r temp--removes read access for Group and Others
users of file temp

30. cal: Calendar


usage: cal [[month] year]- displays the calendar for the current month
options: none
example: cal 1 2001--displays the January calendar for 2001

31. awk: Pattern scanning and processing language


usage: awk [options][file]
options: -f progfile read scan patterns from the file progfile
example: awk '{print $1 + $2}' file1--prints sum of first 2 fields of each line
in file1

32. kill: Terminate a process


usage: kill [options][process-id]
options: -9 to terminate; using "0" for the PID kills all your processes
example: kill -9 0--sends kill signal to processes started since login

33. uname: Display host name and info of current system


usage: uname
options: -r print OS release level | -a prints basic info | -s prints the name of
the OS (default)
example: uname

34.

. Shortcut for current directory path


usage: . as source or destination path
options: none
example: cp ./temp.txt ../temp.txt copies temp.txt from the current directory.
example: ls ./ --lists all files in the current directory

.. Shortcut for parent of current working directory path


usage: .. as source or destination path
options: none
example: cp ../temp.txt ./temp.txt--copies temp.txt from the parent directory.
example: ls ../ --lists all files in the parent directory
example: cd .. --move one directory node up

- Symbolizes stdin
usage: - when used as input path, specifies that input will come from stdin which is the
keyboard
options: none
example: cat - > newfile--whatever you enter from keyboard will be used as input to create the
new file newfile
example: gunzip -c file.tgz | tar xf - --unzip file.tgz to stdout and send it to stdin of tar

~ (tilde): Shortcut for your home path


usage: ~
options: none
example: cd ~ --change from current directory back to your home

> Redirect stdout to a file


usage: > to destination path (file)
options: none
example: man cat > manfiles--route manpage output for cat to a file called manfiles

>> Append redirected stdout to a file


usage: >> append output to an existing file
options: none
example: man lpr >> manfiles--append manpage output for lpr to the existing file called
manfiles

& Place a job in background


usage: & run specified job in background
options: none
example: cc fix32 & --run the C compiler in background

1.
| (pipe) Route output of command to the left of it to input of the command to the right of
it
usage: | followed by a second process
options: none
example: $who | wc -l--count the number of users on the system
example: ls | more--list files in current directory and display them one page at a time
("pipe stdout to more)

Suspend

To suspend a foreground process, type control-Z.

To suspend a background process, you must know its job number. For example,
to suspend background job 2, type:
% stop %2

Resuming a suspended process


• The bg command can be used to resume a suspended process in the
background. When used with no arguments, the bg command will continue
the last suspended job. To resume job number 2, you would type the
command:

% bg %2

• The fg command resumes a suspended process in the foreground. For


example, to resume job 1 in the foreground, you would type this command:

% fg %1

• You can also resume suspended processes by just typing a percent sign (%)
followed by the job number. For example, the command %1 would resume job
1 in the foreground. This command:

% %2&

would resume job 2 in the background, because it ends with an ampersand.

Das könnte Ihnen auch gefallen