..:: Common SSH Commands or Linux Shell Commands ::.. These are some
basic linux commands I most commonly use when administering my linux shell. I work a lot remotely, so I use
Putty or some secure SSH client. From a Linux desktop, you could use X-Terminal.
[indent]
// wall : broadcasts a server wide message
wall "hi" // ls : list files/directories in a directory, comparable to dir in windows/dos.: shows all files (including ones that start with a period), directories, and details attributes for each file.
ls -al // df : shows filesystem and usagedf // cd : change directory · · : go to /usr/local/apache/ directory
cd /usr/local/apache: go to your home directory
cd ~: go to the last directory you were in
cd - : go up a directory cat : print file contents to the screen
cd .. // cat filename.txt : cat the contents of filename.txt to your screen cat filename.txt // tail : like cat, but only reads the end of the file: see the last 20 (by default) lines of /var/log/messages
tail /var/log/messages : watch the file continuously, while it\'s being updated
tail -f /var/log/messages: print the last 200 lines of the file to the screen
tail -200 /var/log/messages // more : like cat, but opens the file one screen at a time rather than all at once : browse through the userdomains file. hit to go to the next page, to quit
more /etc/userdomains // pico : friendly, easy to use file editor : edit the index page for the user\'s website.
pico /home/common/public_html/index.html(Your system may have "nano" which is a pico clone. In that case just replace "pico" with "nano" in the examples.)
// vi : another editor, tons of features, harder to use at first than pico : edit the index page for the user\'s website.
vi /home/common/public_html/index.html // grep : looks for patterns in files : shows all matches of root in /etc/p***wd
grep root /etc/p***wd: shows all lines that do not match root
grep -v root /etc/p***wd // touch : creates an empty file : create an empty file called 404.html in the directory /home/common/public_html/
touch /home/common/public_html/404.html // ln : create\'s "links" between files and directoriesln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf : Now you can edit /etc/httpd.conf rather than the original. changes will affect the orginal, however you can delete the link and it will not delete the original.
// rm : delete a file: deletes filename.txt, will more than likely ask if you really want to delete it
rm filename.txt: deletes filename.txt, will not ask for confirmation before deleting.
rm -f filename.txt: recursively deletes the directory tmp, and all files in it, including subdirectories.
rm -Rf tmp/ BE VERY CAREFULL WITH THIS COMMAND!!! // last : shows who logged in and when: shows only the last 20 logins
last -20: shows last 20 logins, with the hostname in the last field
last -20 -a // w : shows who is currently logged in and where they are logged in from.w // netstat : shows all current network connections.: shows all connections to the server, the source and destination ips and ports.
netstat -an: shows routing table for all ips bound to the server.
netstat -rn // top : shows live system processes in a nice table, memory information, uptime and other useful info. This is excellent for managing your system processes, resources and ensure everything is working fine and your server isn\'t bogged down.top -crun top then type Shift + M to sort by memory usage or Shift + P to sort by CPU usage. Type "q" to quit.
// ps: ps is short for process status, which is similar to the top command. It\'s used to show currently running processes and their PID.A process ID is a unique number that identifies a process, with that you can kill or terminate a running program on your server (see kill command).
: shows processes for a certain user
ps U username: shows all system processes
ps aux: shows all system processes like the above but organizes in a hierarchy that\'s
very useful!ps aux --forest // file : attempts to guess what type of file a file is by looking at it\'s content. : prints out a list of all files/directories in a directory
file * // du : shows disk usage. : shows a summary, in human-readble form, of total disk space used in the current directory, including subdirectories.
du -sh: same thing, but for each file and directory. helpful when finding large files taking up space.
du -sh * // wc : word count: tells how many lines are in filename.txt
wc -l filename.txt // cp : copy a file : copies filename to filename.backup
cp filename filename.backup: copies all files, retaining permissions form one directory to another.
cp -a /home/burst/new_design/* /home/common/public_html/ // kill: terminate a system process: kill -9 (forceful) PID (process) number 431
kill -9 431Use top or ps ux to get system PIDs
[/indent]
Feel free to comment or post more frequestly used shell commands 