Essential Linux Commands

 Touch command

Essential Linux Commands

With out option-create new file
touch file1

If the file doesn’t exist, an empty file with the same name will be created in the current directory

-m : current tme stamp

touch -m ulupeezcontrol.jar

touch -t (mmddhhmm) ulupeezcontrol.jar

if it is current year no need of year,,,,other wise last 2 digits of the year

if you want to copy a timestamp from a file to another file.
touch –r file1 file2

creating empty file
touch ak.txt




•mtime — updated when the file contents change. This is the "default" file time in most cases.
•ctime — updated when the file or its metadata (owner, permissions) change
•atime — updated when the file is read

ls -l mtime ulupeezconrol.jar


scp Command

___________
Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"

scp your_username@rh1.edu:/some/remote/directory/foobar.txt \
your_username@rh2.edu:/some/remote/directory/


GREP Command                                        

Find all lines matching a specific keyword on a file                                                                                                                                                                               

           grep ulupeez /etc/passwd                                                                                             

                                                                                                                  

Option -v, will display all the lines except the match                                                                                                                                                                      

 * To get lines matched the text pattern in a particular file use -c option                     

            grep -c ulupeez /etc/passwd                                                                                                                                                                                                                              

*get the total number of lines that did not match the specific pattern by passing option -cv                      

                                                                                                                  
          grep -cv ulupeez /etc/passwd                                                                                         

*search a text by ignoring the case


          grep -i ulupeez /etc/passwd

*search all subdirectories for a text matching a specific pattern


           grep -ri ulupeez /home/users

Find Command

---------------------

*find files containing a specific word in its name


           find / -type f -size +100M

*find files that are not modified in the last x number of days


          find . -mtime +60

*find files that are modified in the last x number of days

          find . –mtime -2

*delete all the archive files with extension *.tar.gz and greater than 100MB


          find / -type f -name *.tar.gz -size +100M -exec ls -l {} \;
         find / -type f -name *.tar.gz -size +100M -exec rm -f {} \;

*archive all the files that are not modified in the last x number of days


        find /home/ulupeez -type f -mtime +60 | xargs tar -cvf /tmp/`date '+%d%m%Y'_archive.tar`


Post a Comment

If you have any doubts. Let me know

Previous Post Next Post