Unix Commands: Cat Chmod CD CP Date Echo FTP Grep Head Ls LPR Print More Mkdir MV NCFTP FTP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Unix Commands

 cat --- for creating and displaying short files(We can use to create, view and
concatenate files)
 chmod --- change permissions(This command is used to change the
permissions of a file or directory)
 cd --- change directory
 cp --- for copying files
 date --- display date(Use this command to check the date and time)
 echo --- echo argument(The echo command echoes its arguments
 ftp --- connect to a remote machine to download or upload files(Use ftp to
connect to a remote machine, then upload or download files)
 grep --- search file(Use this command to search for information in a file or
files)
 head --- display first part of file
 ls --- see what files you have(Use ls to see what files you have. Your files are
kept in something called a directory.)
 lpr --- standard print command (see also print )( This is the standard Unix
command for printing a file. It stands for the ancient "line printer)
 more --- use to read files(More is a command used to read text files)
 mkdir --- create directory(Use this command to create a directory)
 mv --- for moving and renaming files(Use this command to change the name
of file and directories)
 ncftp --- especially good for downloading files via anonymous ftp.(
Use ncftp for anonymous ftp --- that means you don't have to have a
password.)
 print --- custom print command (see also lpr )( This is a moderately intelligent
print command.)
 pwd --- find out what directory you are in(Use this command to find out what
directory you are working in.)
 rm --- remove a file(Use rm to remove files from your directory.)
 rmdir --- remove directory(Use this command to remove a directory)

rsh --- remote shell(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. This is one of our public workstations and is
fairly fast.)

 setenv --- set an environment variable


 sort --- sort file(Use this commmand to sort a file)
 tail --- display last part of file(Use this command to look at the tail of a file.)
 tar --- create an archive, add or extract files(Use create compressed archives of
directories and files, and also to extract directories and files from an archive)
 telnet --- log in to another machine(Use this command to log in to another
machine from the machine you are currently working on)
 wc --- count characters, words, lines(Use this command to count the number
of characters, words, and lines in a file)

vi

This command starts the vi text editor. To edit a file named myfile in the current
directory, enter:

vi myfile
Command Example Description

1.     ls ls Lists files in current directory


ls -alF List in long format

2.     cd cd tempdir  Change directory to tempdir 


cd ..  Move back one directory 
cd ~dhyatt/web-docs Move into dhyatt's web-docs directory

3.     mkdir mkdir graphics Make a directory called graphics

4.     rmdir rmdir emptydir Remove directory (must be empty)

5.     cp cp file1 web-docs  Copy file into directory


cp file1 file1.bak Make backup of file1

6.     rm rm file1.bak  Remove or delete file


rm *.tmp Remove all file

7.     mv mv old.html new.html Move or rename files

8.     more more index.html Look at file, one page at a time

9.     lpr lpr index.html Send file to printer

10.   man man ls Online manual (help) about command

Ten VALUABLE UNIX Commands


Once you have mastered the basic UNIX commands, these will be quite valuable in
managing your own account. 
Command Example Description

1.     grep <str><files> grep "bad word" * Find which files contain a certain
word

2.     chmod <opt> chmod 644 *.html  Change file permissions read only
<file> chmod 755 file.exe Change file permissions to
executable

3.     passwd passwd Change passwd

4.     ps <opt> ps aux  List all running processes by #ID


ps aux   |   grep dhyatt List process #ID's running by dhyatt

5.     kill <opt> <ID> kill -9 8453 Kill process with ID #8453

6.     gcc (g++) gcc file.c -o file  Compile a program written in C


<source> g++ fil2.cpp -o fil2 Compile a program written in C++

7.     gzip <file> gzip bigfile  Compress file 


gunzip bigfile.gz Uncompress file

8.     mail mail Send file1 by email to someone 


        (pine) [email protected] < file1  Read mail using pine
pine

9.     telnet <host>  telnet vortex.tjhsst.edu  Open a connection to vortex


        ssh <host> ssh -l dhyatt Open a secure connection to jazz as
jazz.tjhsst.edu user dhyatt

10.   ftp <host>  ftp station1.tjhsst.edu  Upload or Download files to


ncftp ncftp metalab.unc.edu station1 
<host/directory> Connect to archives at UNC
Ten FUN UNIX Commands
These are ten commands that you might find interesting or amusing. They are
actually quite helpful at times, and should not be considered idle entertainment. 

Command Example Description

1.     who who Lists who is logged on your machine

2.     finger finger Lists who is on computers in the lab

3.     ytalk ytalk Talk online with dhyatt who is on threat


<user@place> dhyatt@threat

4.     history history Lists commands you've done recently

5.     fortune fortune Print random humerous message

6.     date date Print out current date

7.     cal <mo> <yr> cal 9 2000 Print calendar for September 2000

8.     xeyes xeyes & Keep track of cursor (in "background")

9.     xcalc xcalc & Calculator ("background" process)

10.   mpage <opt> mpage -8 file1 Print 8 pages on a single sheet and send to
<file> |  lpr printer (the font will be small!)

Ten HELPFUL UNIX Commands


These ten commands are very helpful, especially with graphics and word processing
type applications. 
Command Example Description

1.     netscape netscape & Run Netscape browser

2.     xv xv & Run graphics file converter

3.     xfig / xpaint xfig & (xpaint &) Run drawing program

4.     gimp gimp & Run photoshop type program

5.     ispell <fname> ispell file1 Spell check file1

6.     latex <fname> latex file.tex Run LaTeX, a scientific document tool

7.     xemacs / pico xemacs (or pico) Different editors

8.     soffice soffice & Run StarOffice, a full word processor

9.     m-tools (mdir, mcopy,  mdir a: DOS commands from UNIX (dir A:)
        mdel, mformat, etc. ) mcopy file1   a: Copy file1 to A:

10.   gnuplot gnuplot Plot data graphically

Ten USEFUL UNIX Commands:


These ten commands are useful for monitoring system access, or simplifying your
own environment. 

Command Example Description

1.     df df See how much free disk space


2.     du du -b subdir Estimate disk usage of directory in Bytes

3.     alias alias lls="ls -alF" Create new command "lls" for long format
of ls

4.     xhost xhost + Permit window to display from x-window


threat.tjhsst.edu program from threat
xhost - Allow no x-window access from other
systems

5.     fold fold -s file1   |   lpr Fold or break long lines at 60 characters
and send to printer

6.     tar tar -cf subdir.tar subdir Create an archive called subdir.tar of a


tar -xvf subdir.tar directory
Extract files from an archive file

7.     ghostview gv filename.ps View a Postscript file


(gv)

8.     ping ping threat.tjhsst.edu See if machine is alive


   (traceroute) traceroute Print data path to a machine
www.yahoo.com

9.     top top Print system usage and top resource hogs

10.   logout logout or exit How to quit a UNIX shell.


(exit)

Top 10 Commands
• Every UNIX user needs these "top 10"
commands
• cat cd date grep ls more mv ps rm who
• And one of these editors:
– vi or emacs
Basics: cat & more

• cat displays a file with no page breaks


- like DOS type command
- other advanced uses
• more displays a file a screen at a time
- lots of flexibility: q for quit, h for help, multiple
files, etc.

Basics: cd & pwd


• cd changes to a directory
- similar to DOS
- with no argument, to your home directory
- with a directory name, cd’s to that directory
- directory name can be full path (starting with /)
or relative
- paths can include . or ..
• pwd = Print Working Directory

Basics: ls
• ls lists the contents of directories, that is, the
details about files
• ls - short listing (like dir/w)
• ls -l - long listing (dir, explorer list view)
-rw-r--r-- 1 ian wheel 9218 21 Aug 14:49 support.dat
drwxr-xr-x 4 ian admin 136 17 Jan 16:31 talk-others
lrwxr-xr-x 1 ian admin 16 6 Jan 19:31 w -> /shared/w
- Three kinds of things you’ll see: files (”-”),
directories (”d”) and “symlinks” (”l”, like
Aliases or Shortcuts)

ls and Permissions
• UNIX has a more powerful (but complex)
set of permissions than MS-Windows
• Each file or directory has user (owner),
group, and “other” permissions
- Each of which can be r, w or x in any combo
- ls -l shows all this
• The chmod command lets a file’s owner
change its permissions
• If UNIX won’t let you at a file and ls says
it’s there, contact the files’ owner

Basics: cp, mv, rm


• cp is the copy command
• mv is the move/rename command
• These will normally overwrite a file without
warning (on “standard” UNIX)
- Our systems have more safety: should ask for
confirmation if you try to overwrite
• rm deletes files
- Most UNIXes do not have an undelete, so it
asks first

Basics Bonus: mkdir & rmdir


• mkdir & rmdir create and remove
directories
- for mkdir, must not already exist
- for rmdir, directory must be empty

Basics: grep
• grep finds files that contain a specified
pattern
• grep Mark *.txt
• grep -i mark *.txt # -i = ignore case
• Patterns can be more complex
- a good hour-long discussion

- google “unix regular expressions” for detail

Basics: ps & top & kill


• System information commands, like
CTRL/Alt/Delete->Process Manager
• ps lists “your” processes
- options let you see other users’ processes
• top shows all processes, “cpu hogs” at top
• kill can terminate a program

Basic Misc: date, who


• date command prints date & time
• $ date
Tue Jan 25 10:56:54 EST 2005
• UNIX was originally for timesharing
- Might have many (thousands) of users on a
single server (dumb terminals)
- who lists users logged in
$ who
root ttyd1 Jan 24 12:13
baghdadi ttyq0 Jan 24 12:29 (mouse18.phenogenomics.ca)

idarwin ttyq1 Jan 24 19:17 (mouse12.phenogenomics.ca)

Basics Bonus: find & locate


• The find command goes through
directories to find files by name, by age
(what did I call that file I made last
Thursday??), and so on
• It is probably too complex to learn today
- Remember: man find
• The locate command tells you about files
by name only
• $ locate Project42
Basic UNIX Commands

FILE AND RELATED COMMANDS cat file List the contents of file.

More file List the contents of file pausing after each screen
(press Space to continue listing).

Rm file Delete file.

cp file1 file2 Copy the contents of file1 to file2.

mv file1 file2 Move file1 into file2.


Use mv to move a file into or out of directory or to
rename a file.

ls [-la] List files and subdirectories in current working


directory.
If you specify the -l option (that is, the lowercase L
option), more information about each
file/subdirectory will be displayed (file size, last
modification date, file protection code).
If you specify the -a option, a list of all files will be
displayed. (By default, filenames beginning with a
period will not be listed).

grep string file Search file for occurrences of string.

pico file Edit file using the Pico full screen editor (user
friendly).

DIRECTORY COMMANDS cd [directory] Change current working directory to directory.


If directory is not specified, you are sent to your
home directory.

mkdir directory Create a new subdirectory called directory.

rmdir directory Delete a subdirectory called directory; directory


must be empty to be deleted

pwd Displays current working directory.

You might also like