Basic Commands ============== Public domain ******************************************************************************** ### Logging out logout or exit * You can use <ctrl+d> instead. ******************************************************************************** ### Restart the system reboot or shutdown -r now -r reboot after shutdown ******************************************************************************** ### Shutdown the system poweroff or shutdown -h now -h poweroff after shutdown ******************************************************************************** ### Changing Password passwd ******************************************************************************** ### Clear screen clear You can use <ctrl+l> instead. ******************************************************************************** ### Listing Files and Directories ls -lha -l long-listing -h human-readable -a show hidden-entries ******************************************************************************** ### Prompt working directory pwd ******************************************************************************** ### Changing Directory cd return to home directory cd change to previous dir (recall) cd - change to parent dir cd .. ******************************************************************************** ### Displaying directory tree tree ******************************************************************************** ### Determining file types file ******************************************************************************** ### Making Directory mkdir -p for making parent directories as needed. ******************************************************************************** ### Copying files and directories cp -v for verbose -r for recursively copy sub-directories ******************************************************************************** ### Linking Files and Directories ln -s for symbolic links -f remove existing destination files -n treat destination that is a symlink to a directory as if it were a normal file ******************************************************************************** ### Removing Files & Directories rm -f force -r recursively remove sub-directories ******************************************************************************** ### Displaying text files cat more less head tail -f output appended data as the file grows -n show last N lines ******************************************************************************** ### Moving Files and Directories (rename) mv ******************************************************************************** ### Split/Join files: split -b 700m -d --verbose HugeFile PartPrefix -d use numeric suffixes -b put SIZE bytes per output file (k,m) cat PartPrefix* > HugeFile ******************************************************************************** ### Compare files line by line (diff) diff -ruN linux-2.6.18.origin/ linux-2.6.18/ > kernel-2.6.18.patch -r Recursively compare any subdirectories found. -u Output 3 lines of unified context. -N Treat absent files as empty. gzip kernel-2.6.18.patch ******************************************************************************** ### Apply a patch to original file (patch) cp kernel-2.6.18.patch.gz linux-2.6.18/ cd linux-2.6.18/ zcat kernel-2.6.18.patch.gz | patch -p1 ******************************************************************************** ### Changing access permissions chmod mode : u+x,g-r,o-r+wx u user g group o other r read w write x exec + add - del chmod octalMode: 755 nnn ||| ||+-> other |+--> group +---> user rwx ||| ||+-> 1 |+--> 2 +---> 4 755 ||| ||+-> 4+1 -> other: r,x |+--> 4+1 -> group: r,x +---> 4+2+1 -> user : r,w,x -R recursive ******************************************************************************** ### Changng file owner and group chown -R recursive ******************************************************************************** ### Searching the system Shows the full path of (shell) commands. which Locate the binary, source, and manual page files for a command. whereis Indicate how <name> would be interpreted if used as a command name. type -t alias, function, builtin, file, keyword. -a show all executables Search for files in a directory hierarchy find -name -iname case-insensitive name Searching a database instead of entire filesystem updatedb slocate Searching the contents of files grep eth1 /etc/* -r recursively search sub-directories. -i case-insensitive search. -v select non-matching lines. Searching the contents of files with regex (Regular Expression). egrep -v '^#|^ *$' /usr/local/squid/etc/squid.conf ^# Lines which begins with # | Or ^ *$ Empty lines. ******************************************************************************** ### Compress and decompress files compress tar zcvf comp.tar.gz ./dir tar jcvf comp.tar.bz2 ./dir tar Jcvf comp.tar.xz ./dir decompress tar zxvf comp.tar.gz tar jxvf comp.tar.bz2 tar Jxvf comp.tar.xz -z : filter the archive through gzip -c : create a new archive -v : verbosely list files processed -f : use archive file -x : extract files from an archive -j : filter the archive through bzip2 -J : filter the archive through xz-utils ******************************************************************************** ### Processes Display processes ps -A -A Select all processes ps auxw a only yourself u display user-oriented format x must have a tty w wide output ps -ef -e Select all processes -f full-format listing look a process id (PID) pgrep kill processes by PID kill - -TERM terminate -KILL kill -HUP hangup kill processes by name killall ******************************************************************************** ### Getting help display the manual pages man [n] n section number : Section 1 user commands Section 2 system calls Section 3 C library calls Section 4 devices Section 5 file formats and protocols Section 6 games Section 7 conventions, macro packages, etc. Section 8 system administration display info documents info create whatis database makewhatis search whatis database whatis search whatis database apropos documents, HOWTOs, mini-HOWTOs ls /usr/doc/ ******************************************************************************** ### Mount file system mount --bind remount a subtree somewhere else -o loop mount loop device un-mount file system umount eject removable media eject [name] ******************************************************************************** ### Periodically execution watch -n 1 -d "df -h" -n specify an interval -d highlight the differences ******************************************************************************** ### Show routing path traceroute -In 192.9.9.3 -n : Print hop addresses numerically. -I : Use ICMP ECHO instead of UDP datagrams. ******************************************************************************** ### SNMP management values MIB files location ls /usr/share/snmp/mibs show everything snmpwalk -v 1 -c public 192.168.1.1 memory list snmpwalk -v 1 -c public 192.168.1.1 hrStorageDescr process list snmpwalk -v 1 -c public 192.168.1.1 hrSWRunName interface name list snmpwalk -v 1 -c public 192.168.1.1 ifDescr interface MAC list snmpwalk -v 1 -c public 192.168.1.1 ifPhysAddress ******************************************************************************** ### Disk usage control report filesystem disk space usage df -hT -h print sizes in human readable format -T print filesystem type estimate file space usage du -hscS -h print sizes in human readable format -s display only a total for each argument -S do not include size of subdirectories -c produce a grand total du -ha -a write counts for all files, not just directories ******************************************************************************** _BY: Pejman Moghadam_ _TAG: bash, commandline_ _DATE: 2007-09-27 11:05:10_