Some Basic UNIX Commands:
The UNIX operating system has for many years formed the backbone of the Internet, especially for large servers and most major university campuses. However, a free version of UNIX called Linux has been making significant gains against Macintosh and the Microsoft Windows 95/98/NT environments, so often associated with personal computers. Developed by a number of volunteers on the Internet such as the Linux group and the GNU project, much of the open-source software is copyrighted, but available for free. This is especially valuable for those in educational environments where budgets are often limited.
The UNIX operating system has for many years formed the backbone of the Internet, especially for large servers and most major university campuses. However, a free version of UNIX called Linux has been making significant gains against Macintosh and the Microsoft Windows 95/98/NT environments, so often associated with personal computers. Developed by a number of volunteers on the Internet such as the Linux group and the GNU project, much of the open-source software is copyrighted, but available for free. This is especially valuable for those in educational environments where budgets are often limited.
UNIX commands can often be grouped together to make even more powerful commands with capabilities known as I/O redirection ( < for getting input from a file input and > for outputing to a file ) and piping using | to feed the output of one command as input to the next. Please investigate manuals in the lab for more examples than the few offered here.
The following charts offer a summary of some simple UNIX commands. These are certainly not all of the commands available in this robust operating system, but these will help you get started.
The following charts offer a summary of some simple UNIX commands. These are certainly not all of the commands available in this robust operating system, but these will help you get started.
Ten ESSENTIAL UNIX Commands
These are ten commands that you really need to know in order to get started with UNIX. They are probably similar to commands you already know for another operating system.
Ten VALUABLE UNIX Commands
Ten FUN UNIX Commands
Ten HELPFUL UNIX Commands
Ten USEFUL UNIX Commands:
These are ten commands that you really need to know in order to get started with UNIX. They are probably similar to commands you already know for another operating system.
Command
|
Example
|
Description
|
1. ls
|
ls
ls -alF |
Lists files in current directory
List in long format |
2. cd
|
cd tempdir
cd .. cd ~dhyatt/web-docs |
Change directory to tempdir
Move back one directory 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
cp file1 file1.bak |
Copy file into directory
Make backup of file1 |
6. rm
|
rm file1.bak
rm *.tmp |
Remove or delete file
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> <file>
|
chmod 644 *.html
chmod 755 file.exe |
Change file permissions read only
Change file permissions to executable |
3. passwd
|
passwd
|
Change passwd
|
4. ps <opt>
|
ps aux
ps aux | grep dhyatt |
List all running processes by #ID
List process #ID's running by dhyatt |
5. kill <opt> <ID>
|
kill -9 8453
|
Kill process with ID #8453
|
6. gcc (g++) <source>
|
gcc file.c -o file
g++ fil2.cpp -o fil2 |
Compile a program written in C
Compile a program written in C++ |
7. gzip <file>
|
gzip bigfile
gunzip bigfile.gz |
Compress file
Uncompress file |
8. mail
(pine) |
mail me@tjhsst.edu < file1
pine |
Send file1 by email to someone
Read mail using pine |
9. telnet <host>
ssh <host> |
telnet vortex.tjhsst.edu
ssh -l dhyatt jazz.tjhsst.edu |
Open a connection to vortex
Open a secure connection to jazz as user dhyatt |
10. ftp <host>
ncftp <host/directory> |
ftp station1.tjhsst.edu
ncftp metalab.unc.edu |
Upload or Download files to station1
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 <user@place>
|
ytalk dhyatt@threat
|
Talk online with dhyatt who is on 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> <file>
|
mpage -8 file1 | lpr
|
Print 8 pages on a single sheet and send to 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,
mdel, mformat, etc. ) |
mdir a:
mcopy file1 a: |
DOS commands from UNIX (dir 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 + threat.tjhsst.edu
xhost - |
Permit window to display from x-window program from threat
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
tar -xvf subdir.tar |
Create an archive called subdir.tar of a directory
Extract files from an archive file |
7. ghostview (gv)
|
gv filename.ps
|
View a Postscript file
|
8. ping
(traceroute) |
ping threat.tjhsst.edu
traceroute www.yahoo.com |
See if machine is alive
Print data path to a machine |
9. top
|
top
|
Print system usage and top resource hogs
|
10. logout (exit)
|
logout or exit
|
How to quit a UNIX shell.
|
Some Other Useful Pages
- Some Useful Files and UNIX Commands: pipe, fork, system(), etc.
- Getting Started with vi
- The Basics of HTML
- Making a Web Page
- Using LaTeX
- Generating Graphs with GNU Plot
How to check running process (ps -ef command):
Example Uses Of The Linux ps Command
ps command produces a list of the currently running processes on your computer. The ps command is commonly used in conjunction with the grep command and the more or less commands; these additional commands help to filter and paginate the output from ps which can often be quite long.
How to Use the 'ps' Command
On its own, the ps command shows the running processes by the user running it within a terminal window. To invoke ps simply type the following:
ps
The output will show rows of data containing the following information:
- PID
- TTY
- Time
- Command
The PID is the process ID which identifies the running process. The TTY is the terminal type.
On its own, the ps command is quite limited. You probably want to see all the running processes. To view all the running processes use either of the following commands:
ps -A
ps -e
To show all of the processes except for session leaders run the following command:
ps -d
So what is a session leader? When one process kicks off other processes it is the session leader of all the other processes. So imagine process A kicks off process B and process C. Process B kicks off process D and process C kicks off process E. When you list all processes except sessions leaders you will see B, C, D, and E but not A.
Negate any of the selections that you have chosen by using the -N switch. For example, to see just the session leaders run the following command:
ps -d -N
The -N is not helpful when used with the -e or -A switches as it will show nothing at all.
To see only the processes associated with this terminal run the following command:
ps T
If you want to see all the running processes using the following command:
ps r
Selecting Specific Processes Using the ps Command
Return specific processes using the ps command and there are various ways to change the selection criteria.
For instance, if you know the process id you can simply use the following command:
ps -p <pid>
You can select multiple processes by specifying multiple process IDs as follows:
ps -p "1234 9778"
You can also specify them using a comma-separated list:
ps -p 1234,9778
The chances are that you won't know the process ID and it is easier to search by command. To do this use the following command:
ps -C <command>
For example, to see if Chrome is running you can use the following command:
ps -C chrome
Other ways to filter results is by group. Search by group name using the following syntax:
ps -G <groupname> ps --Group <groupname>
For example to find out all the processes being run by the accounts group, type the following:
ps -G "accounts" ps --Group "accounts"
You can also search by group id instead of group name by using a lowercase "g" as follows:
ps -g <groupid> ps --group <groupid>
To search by a list of session IDs use the following command:
ps -s <sessionid>
Alternatively, use the following to search by terminal type.
ps -t <sessionid>
To find all the processes run by a specific user try out the following command:
ps U <userlist>
For example, to find all the processes ran by gary run the following:
ps U "gary"
This output shows the person whose credentials are used to run the command. For example, if you are logged in as gary and run the above command it will show all the commands you've executed.
If you log in as Tom and use sudo to run a command then the above command will show Tom's command as being run by gary and not Tom.
To limit the list to just the processes really run by gary use the following command:
ps -U "gary"
Formatting ps Command Output
By default you get the same four columns when you use the ps command:- PID
- TTY
- Time
- Command
You can get a full listing by running the following command:
ps -ef
The -e, as you know, shows all the processes and the f or -f shows full details.
The columns returned are as follows:
- User ID
- PID
- PPID
- C
- STime
- TTY
- Time
- Command
The User ID is the person who ran the command. The PID is the process ID of the command. The PPID is the parent process that kicked off the command.
The C column shows the number of children a process has. The STime is the start time for the process. The TTY is the terminal, the time is the amount of time it took to run and command is the command that was run.
You can get even more columns by using the following command:
ps -eF
This returns the following columns:
- UID
- PID
- PPID
- C
- SZ
- RSS
- PSR
- STime
- TTY
- Time
- Command
The extra columns are SZ, RSS, and PSR. SZ is the size of the process, RSS is the real memory size and PSR is the processor the command is assigned to.
Specify a user-defined format using the following switch:
ps -e --format <format>
The formats available are as follows:
- %cpu: CPU utilisation
- %mem: Memory percentage utilization
- args: The command with all its arguments
- c: Processor utilization
- cmd: The command
- comm: The command name only
- cp: CPU Usage
- cputime: CPU Time
- egid: Effective group id
- egroup: Effective group
- etime: Elapsed time
- euid: Effective user id
- euser: Effective user
- gid: Group id
- group: Group name
- pgid: Process group id
- pgrp: Process group
- ppid: Parent Process ID
- start: Time the process started
- sz: Size in physical pages
- thcount: Threads owned by the process
- time: Cumulative time
- uid: User Id
- uname: Username
There are many more options but these are the most commonly used ones.
To use the formats type the following:
ps -e --format="uid uname cmd time"
Mix and match the items as you wish them to be.
Sorting Output
To sort the output, use the following notation:
ps -ef --sort <sortcolumns>
The choice of sort options are as follows:
- cmd: Executable name
- pcpu: CPU utilization
- flags: Flags
- pgrp: Process group id
- cutime: Cumulative user time
- cstime: Cumulative system time
- utime: User time
- pid: Process ID
- ppid: Parent process ID
- size: Size
- uid: User ID
- user: User Name
Again there are more options available but these are the most common ones.
An example sort command is as follows:
ps -ef --sort user,pid
Using 'ps' with 'grep', 'less', and 'more' Commands
It's common to use ps with the grep, less and more commands.
The less and more commands help you sift through the results one page at a time. To use these commands simply pipe the output from grep into them as follows:
ps -ef | more ps -ef | less
The grep command helps you filter the results from the ps command.
For example:
ps -ef | grep chrome
Summary
The ps command is commonly used for listing processes within Linux. You can also use the top command to display running processes in a different manner.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.