vaheeD khoshnouD

linux, mikrotik, macosx

Basic Commands

Written by vaheeD on December 28, 2012
5.00 avg. rating (94% score) - 1 vote

Logging out



  • You can use <ctrl+d> instead.

Restart the system



shutdown -r now

-r reboot after shutdown

Shutdown the system



shutdown -h now

-h poweroff after shutdown

Changing Password


Clear screen


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


Changing Directory

cd <dirName>

return to home directory


change to previous dir (recall)

cd -

change to parent dir

cd ..

Displaying directory tree


Determining file types

file <filename>

Making Directory

mkdir <newDir>

-p for making parent directories as needed.

Copying files and directories

cp <source> <destination>

-v for verbose
-r for recursively copy sub-directories

Linking Files and Directories

ln <target> <linksName>

-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 <files>

-f force
-r recursively remove sub-directories

Displaying text files

cat <file>
more <file>
less <file>
head <file>
tail <file>

-f output appended data as the file grows
-n show last N lines

Moving Files and Directories (rename)

mv <source> <destination>

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> <file>

     mode : u+x,g-r,o-r+wx  
            u user  
            g group  
            o other  
            r read  
            w write  
            x exec  
            + add  
            - del  

chmod <octalMode> <file>
      octalMode: 755
         ||+-> other
         |+--> group
         +---> user
         ||+-> 1
         |+--> 2
         +---> 4
         ||+-> 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 <owner:group> <file>

-R recursive

Searching the system

Shows the full path of (shell) commands.

which <programname>

Locate the binary, source, and manual page files for a command.

whereis <filename>

Indicate how <name> would be interpreted if used as a command name.

  type <name>

-t alias, function, builtin, file, keyword.
-a show all executables

Search for files in a directory hierarchy

find <path> -name <pattern>

-iname case-insensitive name

Searching a database instead of entire filesystem

slocate <searchString>

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


tar zcvf comp.tar.gz  ./dir
tar jcvf comp.tar.bz2 ./dir
tar Jcvf comp.tar.xz  ./dir


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


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 <name>

kill processes by PID

kill -<signal> <pid>

-TERM terminate
-KILL kill
-HUP hangup

kill processes by name

killall <name>

Getting help

display the manual pages

man [n] <name>

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 <name>

create whatis database


search whatis database

whatis <keyword>

search whatis database

apropos <string>

documents, HOWTOs, mini-HOWTOs

ls /usr/doc/

Mount file system

mount <device> <dir>
    --bind remount a subtree somewhere else 
    -o loop   mount loop device

un-mount file system

umount <dir>

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

-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

memory list

snmpwalk -v 1 -c public hrStorageDescr

process list

snmpwalk -v 1 -c public hrSWRunName

interface name list

snmpwalk -v 1 -c public ifDescr

interface MAC list

 snmpwalk -v 1 -c public 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


5.00 avg. rating (94% score) - 1 vote

Posted Under: Linux, Macosx

About vaheeD

Leave a Reply

Your email address will not be published. Required fields are marked *

Protected by WP Anti Spam