10 Most useful Linux commands

  1. cat : - It can read, concatenate, and write file contents to the standard output.

    Syntax: cat [options] file_name

    • cat -n : add a number line to each line.

    • cat -e : add $ at the end of the line.

cat file1.txt file2.txt : concatenate files content in the sequence they are passed.

  1. chmod : used to change the access permissions of files and directories.It takes three main arguments: r, w, and x, which stand for read, write, and execute, respectively.

    • u: User, meaning the owner of the file.

    • g: Group, meaning members of the group the file belongs to.

    • o: Others, meaning people not governed by the u and g permissions.

    • a: All, meaning all of the above.

    • r: Read permissions. The file can be opened, and its content viewed.

    • w: Write permissions. The file can be edited, modified, and deleted.

    • x: Execute permissions. If the file is a script or a program, it can be run (executed).

  2. history : list down all the commands you have used till now.

    history 10 – Will give you the last 10 executed commands.

  3. rm: used to remove files/directories. To remove a folder rm use -r

    as a folder is a combination of files/directories so we need to delete recursively.

  4. touch : use to create empty files as well as update existing files/directories' timestamps.

    • -c : no new file is created .it only changes the timestamps of an existing file.

    • -a : updates the access time.

    • -m : change both modify time and change time of an existing file.

  5. ls : used to list all the files/directories present in the current working directories.

    • -l : tells ls to print files in a long listing format.

    • -a : display all files including the hidden files.

    • -R : display the contents of the subdirectories recursively.

    • -1 : produce listing in a single line.

    • -A: display all files including the hidden files except . and ..

  6. tail : displays the last part (10 lines by default) of one or more files.

    • -n : to specify the number of lines

    • -c : to specify the number of bytes

  7. head : works similarly to tail command just print data from top .just replace the tail with head command.

  8. diff : helps to find out the difference between two files.

  9. grep : stands for Global Regular Expression Print. it is a tool used to search for a string of characters in a specified file.it is case-sensitive

    • -w : to search for the exact match of the given word.

    • -i : ignore the upper and lower case while searching.

    • -c : print how many times the given keyword is present in the file.

    • -v : search everything except the given pattern/keyword.

    • -n : prints the line no of matches of a given keyword in a file

Thank you for reading!!

~Sujata Kumari

Great initiative by the #trainwithshubham community.