Posted in General Programming

Linux – bash ( commonly used commands )

I know no one really reads my blog , so here is again another note to myself on commonly used  linux commands for the heck of it ! . Hopefully someones finds it useful . Hoping that writing this down refreshes my frail memory

Getting help

$ # try --help with the command 
$ man <command name> 
$ info <command name> 
$ apropos <command name> 

Listing Directories

$ls -a #lists all files
$ls -l #long listing
$ls -t # time
$ls -s # size
$ls -r # reverse
$ ls -ar # combination

Changing Directories

$pwd # returns the current directory
$cd  <dirname> # change directory to the given directory

Copying files

$cp
$cp -r   #recursive copy
$cp -i   #interactive

Creating/Removing directories

$mkdir    #Creates
$rmdir    #Removes

Displaying file contents

$cat <file1> <file2> <file3>
$more <file1> <file2> <file3>
$less <file1> <file2>  <file3> # you do more with less ! 
$head -n  <file> # top n lines of the file 
$tail -n <file> #bottom n lines of the file 

Pattern matching with grep

$grep <pattern> <files> 
$grep -i <pattern> <files> #case insensitive 

Sorting

$sort <filename> 
$sort -r <filename> #sort in reverse 

Sed

$# See : http://www.regular-expressions.info/ , sed can be used to parsing text and performing various transformations
$sed 's/<pattern>/<pattern to replace> <filename>
$#man  sed 

Symbolic Links

$ln -s <filename> <link name> #soft link , omit -s for hard links

Changing Permissions

$chmod <permissions> <files> #  permissions - a,b,c = r*4+w*2+x
  

Switch Users

$su (switch user)
  

Tee send output to 2 devices

$tee [a]  file
  

Fill standard output with same thing

$yes <string> | <command>
  

Useful process control commands

$jobs
$fg
$bg
$kill <pid>
$ps
  

Environment Variables

$export varname = value
  

Shortcuts with alias

$alias ls='ls la'
  

which is the executable

$which commandname
  

Disk utilities

$du # disk usage
$df # disk free 
  

Compression utilities

$gzip / gunzip
$tar 
$bunzip2
$lzma / unlzma
  

Checking integrity

$md5sum
  

File Comparison

$diff
  

Location of files

$find  <path>  -name <name>
$locate <filename>
  

Downloading websites offline

$wget
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s