Home > Linux > Linux Commands

Linux Commands

  • Include Date in a file name – we will create a file named report.date – On the command prompt check these commands out. Check out other date formats from man pages – The outermost pair of quotes tells shell to execute the command and substitute result in the place. The inner quotes are used to stop shell from interpreting  it before the date command gets to it
      date
      date '+%d%m%y'
      touch ~/Desktop/report.`date '+%d%m%y'`
  • Rsync 2 local folders
      mkdir ~/Desktop/test1
      mkdir ~/Desktop/test2
      cd ~/Desktop/test1
      touch file1.txt
      rsync -avz --stats  ~/Desktop/test1/ ~/Desktop/test2/
  • Add an existing user to an existing Supplementary group
      useradd -G group_name user_name
  • Transfer first “n” lines from one file to another
      head -n oldfile > newfile
      Example: To transfer first 100 lines from oldfile.txt to newfile.txt
      head -100 oldfile.txt > newfile.txt
  • Recursively Copy hidden files
      cp -r source-dir/ destination-dir/
  • Print number of lines, words, characters, bytes in a file
      wc --bytes file-name 
      wc --chars file-name
      wc --lines file-name
      wc --max-line-length file-name
      wc --words file-name 
      wc --bytes file-name
  • Find the number of files in a directory ( recursively )
      find directory-name | wc --lines
  • Find the number of files in a directory ( no recursion + folders are counted as files )
      find directory-name -maxdepth 1 | wc --lines
  • Execute multiple commands in a single line
      (command1 &); (command2 &); (command3 &);
  • Add an existing user to an existing group
      usermod -aG groupname username 

      [ the "-a" flag is very important here, it appends the new group to the users existing list of supplementary groups - 
        if you do not use the "-a" flag, then all of the users supplementary groups will be replaced with the new group ]
Categories: Linux
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: