0% found this document useful (0 votes)
66 views8 pages

Unix Basic Commands

The document provides a summary of basic UNIX commands organized into the following categories: 1. Files - Commands for working with files like ls, more, emacs, mv, cp, rm, diff, wc, chmod, gzip, gunzip, gzcat, lpr, lpq, and lprm. 2. Directories - Commands for working with directories like mkdir, cd, and pwd. 3. Finding things - Commands for finding files and strings like ff and grep. 4. About other people - Commands for getting information about other users like w, who, finger, last, talk, write, and elm. 5. About your self - Commands for

Uploaded by

Msaki
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
66 views8 pages

Unix Basic Commands

The document provides a summary of basic UNIX commands organized into the following categories: 1. Files - Commands for working with files like ls, more, emacs, mv, cp, rm, diff, wc, chmod, gzip, gunzip, gzcat, lpr, lpq, and lprm. 2. Directories - Commands for working with directories like mkdir, cd, and pwd. 3. Finding things - Commands for finding files and strings like ff and grep. 4. About other people - Commands for getting information about other users like w, who, finger, last, talk, write, and elm. 5. About your self - Commands for

Uploaded by

Msaki
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 8

UNIX BASIC COMMANDS:

Files

 ls --- lists your files


ls -l --- lists your files in 'long format', which contains lots of useful information, e.g. the exact
size of the file, who owns the file and who has the right to look at it, and when it was last
modified.
ls -a --- lists all files, including the ones whose filenames begin in a dot, which you do not always
want to see.
There are many more options, for example to list files by size, by date, recursively etc.
 more filename --- shows the first part of a file, just as much as will fit on one screen. Just hit the
space bar to see more or q to quit. You can use /pattern to search for a pattern.
 emacs filename --- is an editor that lets you create and edit a file. See the emacs page.
 mv filename1 filename2 --- moves a file (i.e. gives it a different name, or moves it into a
different directory (see below)
 cp filename1 filename2 --- copies a file
 rm filename --- removes a file. It is wise to use the option rm -i, which will ask you for
confirmation before actually deleting anything. You can make this your default by making an
alias in your .cshrc file.
 diff filename1 filename2 --- compares files, and shows where they differ
 wc filename --- tells you how many lines, words, and characters there are in a file
 chmod options filename --- lets you change the read, write, and execute permissions on your
files. The default is that only you can look at them and change them, but you may sometimes
want to change these permissions. 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. Note that for
someone to be able to actually look at the file the directories it is in need to be at least
executable. See help protection for more details.
 File Compression
o gzip filename --- compresses files, so that they take up much less space. Usually text
files compress to about half their original size, but it depends very much on the size of
the file and the nature of the contents. There are other tools for this purpose, too (e.g.
compress), but gzip usually gives the highest compression rate. Gzip produces files with
the ending '.gz' appended to the original filename.
o gunzip filename --- uncompresses files compressed by gzip.
o gzcat filename --- lets you look at a gzipped file without actually having to gunzip it
(same as gunzip -c). You can even print it directly, using gzcat filename | lpr
 printing
o 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', or if you're at CSLI, you may want to use 'lpr -Pcord115-d'. See 'help
printers' for more information about printers and their locations.
o 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
o 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.
o 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.
o dvips filename --- print .dvi files (i.e. files produced by LaTeX). You can use dviselect to
print only selected pages. See the LaTeX page for more information about how to save
paper when printing drafts.

Directories
Directories, like folders on a Macintosh, are used to group files together in a hierarchical structure.

 mkdir dirname --- make a new directory


 cd dirname --- change directory. You basically 'go' to another directory, and you will see the files
in that directory when you do 'ls'. You always start out in your 'home directory', and you can get
back there by typing 'cd' without arguments. 'cd ..' will get you one level up from your current
position. You don't have to walk along step by step - you can make big leaps or avoid walking
around by specifying pathnames.
 pwd --- tells you where you currently are.

Finding things

 ff --- find files anywhere on the system. This can be extremely useful if you've forgotten in which
directory you put a file, but do remember the name. In fact, if you use ff -p you don't even need
the full name, just the beginning. This can also be useful for finding other things on the system,
e.g. documentation.
 grep string filename(s) --- looks for the string in the files. This can be useful a lot of purposes,
e.g. finding the right file among many, figuring out which is the right version of something, and
even doing serious corpus work. grep comes in several varieties (grep, egrep, and fgrep) and has
a lot of very flexible options. Check out the man pages if this sounds good to you.

About other people

 w --- tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This
allows you to see whether they're actually sitting there typing away at their keyboards right at
the moment.
 who --- tells you who's logged on, and where they're coming from. Useful if you're looking for
someone who's actually physically in the same building as you, or in some other particular
location.
 finger username --- gives you lots of information about that user, e.g. when they last read their
mail and whether they're logged in. Often people put other practical information, such as phone
numbers and addresses, in a file called .plan. This information is also displayed by 'finger'.
 last -1 username --- tells you when the user last logged on and off and from where. Without any
options, last will give you a list of everyone's logins.
 talk username --- lets you have a (typed) conversation with another user
 write username --- lets you exchange one-line messages with another user
 elm --- lets you send e-mail messages to people around the world (and, of course, read them).
It's not the only mailer you can use, but the one we recommend. See the elm page, and find out
about the departmental mailing lists (which you can also find in /user/linguistics/helpfile).

About your (electronic) self

 whoami --- returns your username. Sounds useless, but isn't. You may need to find out who it is
who forgot to log out somewhere, and make sure *you* have logged out.
 finger & .plan files
of course you can finger yourself, too. That can be useful e.g. as a quick check whether you got
new mail. Try to create a useful .plan file soon. Look at other people's .plan files for ideas. The
file needs to be readable for everyone in order to be visible through 'finger'. Do 'chmod a+r
.plan' if necessary. You should realize that this information is accessible from anywhere in the
world, not just to other people on turing.
 passwd --- lets you change your password, which you should do regularly (at least once a year).
See the LRB guide and/or look at help password.
 ps -u yourusername --- lists your processes. Contains lots of information about them, including
the process ID, which you need if you have to kill a process. Normally, when you have been
kicked out of a dialin session or have otherwise managed to get yourself disconnected abruptly,
this list will contain the processes you need to kill. Those may include the shell (tcsh or whatever
you're using), and anything you were running, for example emacs or elm. Be careful not to kill
your current shell - the one with the number closer to the one of the ps command you're
currently running. But if it happens, don't panic. Just try again :) If you're using an X-display you
may have to kill some X processes before you can start them again. These will show only when
you use ps -efl, because they're root processes.
 kill PID --- kills (ends) the processes with the ID you gave. This works only for your own
processes, of course. Get the ID by using ps. If the process doesn't 'die' properly, use the option
-9. But attempt without that option first, because it doesn't give the process a chance to finish
possibly important business before dying. You may need to kill processes for example if your
modem connection was interrupted and you didn't get logged out properly, which sometimes
happens.
 quota -v --- show what your disk quota is (i.e. how much space you have to store files), how
much you're actually using, and in case you've exceeded your quota (which you'll be given an
automatic warning about by the system) how much time you have left to sort them out (by
deleting or gzipping some, or moving them to your own computer).
 du filename --- shows the disk usage of the files and directories in filename (without argument
the current directory is used). du -s gives only a total.
 last yourusername --- lists your last logins. Can be a useful memory aid for when you were
where, how long you've been working for, and keeping track of your phonebill if you're making a
non-local phonecall for dialling in.

Connecting to the outside world

 nn --- allows you to read news. It will first let you read the news local to turing, and then the
remote news. If you want to read only the local or remote news, you can use nnl or nnr,
respectively. To learn more about nn type nn, then \tty{:man}, then \tty{=.*}, then \tty{Z}, then
hit the space bar to step through the manual. Or look at the man page. Or check out the
hypertext nn FAQ - probably the easiest and most fun way to go.
 rlogin hostname --- lets you connect to a remote host
 telnet hostname --- also lets you connect to a remote host. Use rlogin whenever possible.
 ftp hostname --- lets you download files from a remote host which is set up as an ftp-server. This
is a common method for exchanging academic papers and drafts. If you need to make a paper of
yours available in this way, you can (temporarily) put a copy in /user/ftp/pub/TMP. For more
permanent solutions, ask Emma. The most important commands within ftp are get for getting
files from the remote machine, and put for putting them there (mget and mput let you specify
more than one file at once). Sounds straightforward, but be sure not to confuse the two,
especially when your physical location doesn't correspond to the direction of the ftp connection
you're making. ftp just overwrites files with the same filename. If you're transferring anything
other than ASCII text, use binary mode.
 lynx --- lets you browse the web from an ordinary terminal. Of course you can see only the text,
not the pictures. You can type any URL as an argument to the G command. When you're doing
this from any Stanford host you can leave out the .stanford.edu part of the URL when
connecting to Stanford URLs. Type H at any time to learn more about lynx, and Q to exit.

Miscellaneous tools

 webster word --- looks up the word in an electronic version of Webster's dictionary and returns
the definition(s)
 date --- shows the current date and time.
 cal --- shows a calendar of the current month. Use e.g., 'cal 10 1995' to get that for October 95,
or 'cal 1995' to get the whole year.

Basic Shell Commands


Jeremy Sanders

October 2010

1. acroread - Read or print a PDF file.


2. cat - Send a file to the screen in one go. Useful for piping to other programs
3. cat file1 # list file1 to screen
4. cat file1 file2 file3 > outfile # add files together into outfile
5. cat *.txt > outfile # add all .txt files together
6. cat file1 file2 | grep fred # pipe files
7. cc - Compile a C program
8. cc test1.c # compile test1.c to a.out
9. cc -O2 -o test2.prog test2.c # compile test2.c to test2.prog
10. cd - Change current directory
11. cd # go to home directory
12. cd ~/papers # go to /home/user/papers
13. cd ~fred # go to /home/fred
14. cd dir # go to directory (relative)
15. cd /dir1/dir2/dir3... # go to directory (absolute)
16. cd - # go to last directory you were in
17. cp - Copy file(s)
18. cp file1 file2 # copy file1 to file2
19. cp file1 directory # copy file1 into directory
20. cp file1 file2 file3 ... directory # copy files into directory
21. cp -R dir1 dir2/ # copy dir1 into dir2 including subdirectries
22. cp -pR dir1 dir2/ # copy directory, preserving permissions
23. date - Shows current date
24. > date
25. Sat Aug 31 17:18:53 BST 2002
26. dvips - Convert a dvi file to PostScript
27. dvips document.dvi # convert document.dvi to document.ps
28. dvips -Ppdf document.dvi # convert to ps, for conversion to pdf
29. emacs - The ubiquitous text editor
30. emacs foo.txt # open file in emacs
31. emacsclient foo.txt # open file in existing emacs (need to use
32. # M-x start server first)
33. file - Tells you what sort of file it is
34. > file temp_70.jpg
35. temp_70.jpg: JPEG image data, JFIF standard 1.01,
36. resolution (DPI), 72 x 72
37. firefox - Start Mozilla Firefox
38. f77/f90 - Compile a Fortran 77/99 program
39. f77 -O2 -o testprog testprog.f
40. gedit - Gnome text editor
41. gnuplot - A plotting package.
42. grep - Look for text in files. List out lines containing text (with filename if more than one
file examined).
43. grep "hi there" file1 file2 ... # look for 'hi there' in files
44. grep -i "hi there" filename # ignore capitals in search
45. cat filename | grep "hi there" # use pipe
46. grep -v "foo" filename # list lines that do not include foo
47. gtar - GNU version of the tar utility (also called tar on Linux). Store directories and files
together into a single archive file. Use the normal tar program to backup files to a tape.
See info tar for documentation.
48. gtar cf out.tar dir1 # put contents of directory into out.tar
49. gtar czf out.tar.gz dir1 # write compressed tar, out.tar.gz
50. gtar tf in.tar # list contents of in.tar
51. gtar tzf in.tar.gz # list contents of compressed in.tar.gz
52. gtar xf in.tar # extract contents of in.tar here
53. gtar xzf in.tar.gz # extract compressed in.tar.gz
54. gtar xf in.tar file.txt ... # extract file.txt from in.tar
55. gv - View a Postscript document with Ghostscript.
56. gzip / gunzip - GNU Compress files into a smaller space, or decompress .Z or .gz
files.
57. gzip file.fits # compresses file.fits into file.fits.gz
58. gunzip file.fits.gz # recovers original file.fits
59. gzip *.dat # compresses all .dat files into .dat.gz
60. gunzip *.dat.gz # decompresses all .dat.gz files into .dat
61. program | gzip > out.gz # compresses program output into out.gz
62. program | gunzip > out # decompresses compressed program output
63. info - A documentation system designed to replace man for GNU programs (e.g. gtar,
gcc). Use cursor keys and return to go to sections. Press b to go back to previous section.
A little hard to use.
64. info gtar # documentation for gtar
65. kill - Kill, pause or continue a process. Can also be used for killing daemons.
66. > ps -u jss
67. ...
68. 666 pts/1 06:06:06 badprocess
69. > kill 666 # this sends a ``nice'' kill to the
70. # process. If that doesn't work do
71. > kill -KILL 666 # (or equivalently)
72. > kill -9 666 # which should really kill it!
73.
74. > kill -STOP 667 # pause (stop) process
75. > kill -CONT 667 # unpause process
76. latex - Convert a tex file to dvi
77. logout - Closes the current shell. Also try ``exit''.
78. lp - Sends files to a printer
79. lp file.ps # sends postscript file to the default printer
80. lp -dlp2 file.ps # sends file to the printer lp2
81. lp -c file.ps # copies file first, so you can delete it
82. lpstat -p lp2 # get status and list of jobs on lp2
83. cancel lp2-258 # cancel print job lp2-258
84.
85. lpr -Plp2 file.ps # send file.ps to lp2
86. lpq -Plp2 # get list of jobs on lp2
87. lprm -Plp2 1234 # delete job 1234 on lp2
88. ls - Show lists of files or information on the files
89. ls file # does the file exist?
90. ls -l file # show information about the file
91. ls *.txt # show all files ending in .txt
92. ls -lt # show information about all files in date order
93. ls -lrt # above reversed in order
94. ls -a # show all files including hidden files
95. ls dir # show contents of directory
96. ls -d dir # does the directory exist?
97. ls -p # adds meaning characters to ends of filenames
98. ls -R # show files also in subdirectories of directory
99. ls -1 # show one file per line
100. man - Get instructions for a particular Unix command or a bit of Unix. Use space
to get next page and q to exit.
101. man man # get help on man
102. man grep # get help on grep
103. man -s1 sort # show documentation on sort in section 1
104. more - Show a file one screen at a time
105. more file # show file one screen at a time
106. grep 'frog' file | more # Do it to output of other command
107. mv - Move file(s) or rename a file
108. mv file1 file2 # rename file1 to file2
109. mv dir1 dir2 # rename directory dir1 to dir2
110. mv file1 file2 file3 ... directory # move files into directory
111. nano - very simple text editor. Warning - this program can introduce extra line
breaks in your file if the screen is too narrow!
112. nice - Start a process in a nice way. Nice levels run from -19 (high priority) to 19
(low priority). Jobs with a higher priority get more CPU time. See renice for more detail.
You should probably be using the grid-engine to run long jobs.
113. nice +19 myjob1 # run at lowest priority
114. nice +8 myjob2 # run at lowish priority
115. openoffice.org - a free office suite available for Linux/Unix, Windows and
Mac OS X.
116. passwd - change your password
117. pine - A commonly used text-based mail client. It is now called alpine. Allows
you to send and receive emails. Configuration options allow it to become quite powerful.
Other alternatives for mail are mozilla mail and mutt, however I suggest you stick to
alpine or thunderbird.
118. printenv - Print an environment variable in tcsh
119. setenv MYVARIABLE Fred
120. printenv MYVARIABLE
121. printenv # print all variables
122. ps - List processes on system
123. > ps -u jss # list jss's processes
124. 934 pts/0 00:00:00 bash
125. ^^^^^ ^^^^^ ^^^^^^^^ ^^^^^^^
126. PID output CPU time name
127. > ps -f # list processes started here in full format
128. > ps -AF # list all processes in extra full format
129. > ps -A -l # list all processes in long format
130. > ps -A | grep tcsh # list all tcsh processes
131. pwd - Show current working directory
132. > pwd
133. /home/jss/writing/lecture
134. quota - Shows you how much disk space you have left
135. > quota -v
136. ...
137. renice - Renice a running process. Make a process interact better with other
processes on the system (see top to see how it is doing). Nice levels run from -19 (high
priority) to 19 (low priority). Only your own processes can be niced and they can only be
niced in the positive direction (unless you are root). Normal processes start at nice 0.
138. > ps -u jss | grep bigprocess # look for bigprocess
139. 1234 pts/0 99:00:00 bigprocess
140. > renice 19 1234 # renice PID 1234 to 19
141. rm - Delete (remove) files
142. rm file1 # delete a file (use -i to ask whether sure)
143. rm -r dir1 # delete a directory and everything in it (CARE!)
144. rm -rf dir1 # like above, but don't ask if we have a -i alias
145. rmdir - Delete a directory if it is empty (rm -r dirname is useful if it is not
empty)
146. rmdir dirname
147. staroffice - An office suite providing word processor, spreadsheet, drawing
package. See Users' Guide on how to install this. This is a commercial version of the
openoffice office package - use openoffice.org on linux.
148. setenv - Set an environment variable in tcsh.
149. setenv MYVARIABLE Fred
150. echo Hi there $MYVARIABLE
151. tar - Combine files into one larger archive file, or extract files from that archive
(same as gtar on Linux).
152. tar cvf /dev/rmt/0 ./ # backup cwd into tape
153. tar tvf /dev/rmt/0 # list contents of tape
154. tar xvf /dev/rmt/0 # extract contents of tape
155. thunderbird - Start mozilla thunderbird.
156. top - Interactively show you the ``top'' processes on a system - the ones
consuming the most computing (CPU) time. Press the ``q'' key in top to exit. Press the
``k'' key to kill a particular process. Press ``r'' to renice a process.

You might also like