must know linux commands for developers

    By: Thad Mertz
    2 years ago

    Must know linux commands for developers


    Hi devs in this article we are going to see most important commands offered by linux. You can improve your productivity using these linux commands. Lets see what linux has to offer.


    Check linux version.

    uname -a
    


    Find file with name Resident.php in current and sub directories


    find . -name Resident.php
    


    Search for directory - folder


    find / -type d -name 'folder name'
    


    Move file in same parent folder's sub folder


    So here we are moving "laravel.log" file from logs folder to test folder.

    find logs -maxdepth 1 -name "laravel.log" -exec mv {} test \;
    
    find logs -name 'laravel.log' -exec sh -c 'mv "$@" test' find-sh {} +
    
    // Moving back to logs folder
    find storage/test -maxdepth 1 -name "laravel.log" -exec mv {} storage/logs \;
    


    Find a file in sub folders and move to desktop


    find folderName -name fileName -exec sh -c 'mv "$@" FolderNameWhereYouWantToMove' find-sh {} +;
    
    // This will search file "fileName" under "folderName" directory and then will move to "FolderNameWhereYouWantToMove" folder
    


    Create a file add text in it.


    echo write something to file.txt | cat > file.txt
    


    Append text to a file.


    echo -e write something to file.txt >> file.txt 
    
    // will add "write something to file.txt" string in "file.txt" file.
    


    Clearing file content.


     > file.txt
    
    // will remove the content of file.txt
    
    

    Clear file and add txt again (Running one command after another)


    > file.txt && echo -e write something to file.txt >> file.txt
    
    // Here first we are empty a file and then add a string in it
    
    // so 2 commands run 
    
    1st : > file.txt // clears the file
    2nd : echo -e write something to file.txt >> file.txt  // adds "something to file.txt" to file
    



    Combine Content from multiple files and output in single file


    cat file.txt file1.txt > 0.txt
    
    // will add content of file.txt and file1.txt and put in new file 0.txt
    


    Move all files from one folder to another


    mv storage/test/* storage/logs/ 
    


    Create multiple folder inside a folder

    mkdir -p test/{0..4}
    

    Here command will create folders inside "test" folder. as we mentioned {0..4} we will see 5 folder from 0,1,2,3,4.


    Empty A folder

    rm -rf test/*
    

    This command will remove all files and folders from "test" folder.