{"id":25724497,"url":"https://github.com/deroyace/linux-cmds","last_synced_at":"2025-06-13T03:35:46.583Z","repository":{"id":130559613,"uuid":"459625376","full_name":"DeRoyace/Linux-cmds","owner":"DeRoyace","description":"Basic Linux terminal commands for beginners","archived":false,"fork":false,"pushed_at":"2024-06-21T19:00:17.000Z","size":988,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-07T05:09:57.504Z","etag":null,"topics":["cheatsheet","cli","command-line","linux","linux-command","linux-command-line","linux-commands-cheatsheet","unix","unix-command"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeRoyace.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-15T14:58:01.000Z","updated_at":"2024-06-21T19:00:21.000Z","dependencies_parsed_at":"2024-06-22T11:07:05.880Z","dependency_job_id":null,"html_url":"https://github.com/DeRoyace/Linux-cmds","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeRoyace%2FLinux-cmds","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeRoyace%2FLinux-cmds/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeRoyace%2FLinux-cmds/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeRoyace%2FLinux-cmds/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeRoyace","download_url":"https://codeload.github.com/DeRoyace/Linux-cmds/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252817627,"owners_count":21808706,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cheatsheet","cli","command-line","linux","linux-command","linux-command-line","linux-commands-cheatsheet","unix","unix-command"],"created_at":"2025-02-25T21:47:20.372Z","updated_at":"2025-05-07T05:10:06.309Z","avatar_url":"https://github.com/DeRoyace.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Linux Commands\n![Linux-cmds](https://socialify.git.ci/DeRoyace/Linux-cmds/image?description=1\u0026font=Bitter\u0026forks=1\u0026issues=1\u0026language=1\u0026name=1\u0026owner=1\u0026pattern=Charlie%20Brown\u0026pulls=1\u0026stargazers=1\u0026theme=Dark)\n\n## ls command\n- `ls`    : to list directories and files\n- `ls -a` : to list all files and directories alongwith hidden ones\n- `ls -r` : lists files and directories in reverse alphabetical order.\n- `ls -l ` : to give detailed info of directories/files like when created and by whom, date modified, size, permissions and ownerships\n- `ls -al` : to list all hidden files with details.\n- `ls -lh` : to list file with details of file size in - KB (kilobytes).\n- `ls -lR` : to list all the directories and their - sub-directories with details.\n- `ls -lR dirName` : to list the details of - sub-directories of the specified dirName.\n- `ls -F` : to identify files and directories - seperately. Directories will be listed with a \"/\" - symbol at the end of directory name\n- `ls -i` : displays the inode [index number] of each - file\n- `ls --sort=t` or  `ls -t` : displays the list of files / directory sorted by time. Similarly sort=v/s/e for sort by version/size/extension\n\n\u003cbr\u003e\n\n## Directory\n\n### Directory Creation\n- `mkdir [FOLDER-NAME]` : to create a folder/ directory\n- `mkdir folder1 folder2 folder3` : to create multiple folders/ directory at once\n- `mkdir file{1..9}` : this will create 10 folders with name 'file 1', 'file 2', ..., 'file 10'\n- `mkdir -v folders{1..7}` : this will create folders \u0026 will skip the ones which are already created before with the same name.\n- `mkdir -p [PATH]` : will create 'cmds' folder in the given path but if the path doesn't exits then it will be created.\n\n### Remove directoy\n- `rmdir [DIR-NAME]` : to remove the file/ folder/ directory.\n- `rmdir myFolder*` : removes all folders that begins with name 'myFolder'\n- `rmdir *` : removes all the folder in the present directory.\n- `rmdir myFolder{1..7}` : removes the folders from 'myFolder 1' to 'myFolder 7'\nNOTE: rmdir cannot delete diectories having files / folders inside.\n- `rm -R [DIR-NAME]` : to delete the directory with the files inside.\n- `rm -r [DIR-NAME]`: to delete all the files and NON-EMPTY directories and also the child folders content.\n\n### Change Directory\n- `cd` : to change directory to home/user directory\n- `cd ~` : to go to home/user directory\n- `cd /` : to go to root directory\n- `cd [DIR-NAME]` : to change directory or go to that directory\n- `cd ..` : to go to the parent directory\n\u003cbr\u003e\n\n## File management\n\n### Create or manipulate file\n- `touch [FILE-NAME]` : to create a file\n- `touch -m [FILE-NAME]` : change  modification  time of the  file\n- `touch -a [FILE-NAME]` : change the access time of the file\n- `touch test{1..5}.txt` : create 5  files with name test1.txt, test2.txt, ..., test5.txt\n- `cat \u003e [FILE-NAME]` : to rewrite a file. If the filename not present then new file with given name will be created\n- `cat \u003e\u003e [FILE-NAME]` : to append new contents to the file\n[ **NOTE**: _for cat \u003e or \u003e\u003e ... commands, inorder to exit writing mode of the file press CTRL+D._]\n\n### Delete files\n- `rm [FILE-NAME]` : to remove dir/ file/ folder.\n-  `rm *` : removes all the files in the current directory. \n-  `rm *.txt` : removes all the files in the current directory that has .txt extension.\n- `rm -i [FILENAME]` : to make command prompt the user with each filename while deleting\n\n### Move and Copy\n- `mv [SOURCE] [DESTINATION]` : to move the file into the given destination or path.\n- `cp [FILE-1] [FILE-2]` : copies the file1 contents to file2.\n- `cp [FILE-NAME]` : will copy the file in the directory.\n\n### Show file contents\n- `cat [FILE-NAME]` : to show the contents of file in the terminals.\n\n### Change filename\n- `mk [PRESENT-FILENAME] [NEW-FILENAME]` : this changes the file or folder name.\n\n### Octal form\n- `od  [FILENAME]` : to display a file contents in octal form\n\n### file command\n- used to display file type\n    ```\n    file video.mp4\n    ```\n    Output:\n    ```\n    video.mp4: ISO Media, MP4 Base Media v1 [ISO 14496-12:2003]\n    ```\n\n### Locate a file\n- `find [FILENAME]` : search for files in a directory hierarchy\n\n\n### File Comparison\n\n#### cmp command\n- Compare two files byte by byte\n    ```\n    cmp file1.txt file2.txt\n    ```\n    Output:\n    ```\n    file1.txt file2.txt differ: byte 8, line 1\n    ```\n#### diff command\n- used to compare files line by line\n    ```\n    diff [FILE-1] [FILE-2]\n    ```    \nExamples:\n- to show the difference of two files side by side\n    ```\n    diff -y file1.txt file2.txt\n    ```\n    - `-y` : side-by-side  output in two columns\n\n#### comm command\n- Used to compare two sorted files\n    \n    Contents of file1.txt :\n    ```\n    ANGULAR\n    DJANGO\n    ELECTRON\n    FLASK\n    NODEJS\n    REACT\n    YARN\n    ```\n    Contents of file2.txt :\n    ```\n    ANGULAR JS\n    FASTAPI\n    FLASK\n    NEXT JS\n    NODEJS\n    REACTJS\n    YARN\n    ```\n    Command line input:\n    ```\n    comm --total file1.txt file2.txt\n    ```\n    Output:\n    ```\n    ANGULAR\n    \t    ANGULAR JS\n    DJANGO\n    ELECTRON\n    \t    FASTAPI\n    \t\t        FLASK\n    \t    NEXT JS\n    \t\t        NODEJS\n    REACT\n    \t    REACTJS\n    \t\t        YARN\n    4\t4\t3\ttotal\n    ```\n\n    - unmatched file of first file is displayed in 1st column\n    - unmatched file of first file is displayed in 2nd column\n    - matched lines in 3rd column\n    - `--total` : counts the number of lines that are matched and unmatched for both the files.\n\n\n### File  Permissions\n\n#### chmod (change mode)\n- use to change permissions of a file or directory of all types of users\n- Control of a file:\n    - `d` : directrory\n    - `-` : no permission given [NOTE: the leftmost `-` implies its a file]\n    - Permissions\n        - `r` : read(4)\n        - `w` : write (2)\n        - `x` : executable (1)\n\n    Example:\n    ```\n    chmod +x program.sh\n    ```\n    The above command grants executable permissions to the program.sh file for all the users\n    ```\n    -rwxrwxr-x  1 deroyace deroyace    127 May 23 15:3 counter.sh\n    drwxr-xr-x  3 deroyace deroyace   4096 Mar 29 19:2 Desktop\n    ```\n    - `rwx` is written 3 times consecutively. This means,\n        - first set of rwx implies **USER / OWNER** permission\n        - second set implies **GROUP** permissions same as owner.\n        - third set implies **OTHERs** outside the group.\n        - left most single symbol `d` indicates it is a directory. It can be `l` or `-` also.\n            - `l` means its a shortcut link of a file or a directory.\n            - `-` means it is a file.\n- **Numerical Short hand or Octal  Mode**\n    - Another way to use chmod is to provide the permissions you wish to give to the owner, group, and others as a three-digit number which is basically octets that are formed by combinations of 4,2 and 1.\n    - The leftmost digit represents the permissions for the owner. \n    - The middle digit represents the permissions for the group members. \n    - The rightmost digit represents the permissions for the others.\n   \n          Value   Symbols    Meanings/ Permissons\n            0       ---       No permission\n            1       --x       Execute\n            2       -w-       Write\n            3       -wx       Write and execute\n            4       r--       Read\n            5       r-x       Read and execute\n            6       rw-       Read and write\n            7       rwx       Read, write, and execute\n        Examples:\n        - Give   read,  write,  execution  permissions to all types of users:\n            ```\n            chmod 777 program.sh\n            ```\n        - Give   read,  write,  execution  permissions only to User and Group:\n            ```\n            chmod 770 program.sh\n            ```\n        - Give   read,  write,  execution  permissions to User and read nad execution permission to Group and only execution permission to  other users:\n            ```\n            chmod 751 program.sh\n            ```\n\n    - Default permissions for:\n        - `file`     : **664** (-rw-rw-r--)\n        - `folder`   : **775** (drwxrwxr-x)\n\n-  **Symbolic Mode**\n    ```\n     Symbol     Meaning\n    -------------------\n       a         all users\n       u         user\n       g         group\n       o         others\n    ```\n    Examples:\n    - Give read, write, execute permission to user and execute permission to group and other\n        ```\n        chmod u+rwx,go+x program.sh\n        ```\n    - Give read permission to all, write permission to  user and group, execute persmission to group only:\n        ```\n        chmod u+rw,g+rx,o+r program.sh\n        ```\n    - Give read, write, execute permission to user and execute permission to group and other:\n        ```\n        chmod u+rwx,go+x program.sh\n        ```\n    -  Make all files and sub-directories in the directory TEST executable by all users\n        ```\n        chmod -R a+x TEST\n        ```\n    - Remove executable  permission from group and other of a file\n        ```\n        chmod go-x file.txt\n        ```\n\n#### chgrp (change group)\n- `chgrp [GROUP-NAME] [FILE/FOLDER NAME]`\n : to assign a file/folder to a specific group\n\u003cbr\u003e\n\n#### chown (change owner)\n-  `sudo chown [USER-NAME] [FILE/FOLDER-NAME]`\n :  to change the user or ownership of a file/folder:\n\n### File Compression\n\n####  tar command\n- it is used to  compress and archive files\n- **TAR** short for Tape Archive\n\nExamples:\n\n- To create a tar and includes the files specified in the command:\n    ```\n    tar cf file.tar [FILE-NAMES]\n    ```\n    - `c` : create new archive\n    - `f` : to specify name of the archive files\n    - `[FILE-NAMES]` : represent files that are to be included in the tar file\n\n- Extract From tar Archive\n    ```\n    tar xf file.tar\n    ```\n    - `x` : extract files from an archive\n\n- Creating an uncompressed tar Archive:\n\n    ```\n    tar cvf file.tar *.sh\n    ```\n    - This command creates a **tar** file called `file.tar` which is the **Archive** of all `.sh` files in the current directory.\n    - `v` : verbosely  list  files processed\n\n- Extracting from uncompressed tar archive:\n    ```\n    tar xvf file.tar\n    ```\n\n- Create a tar.gz Compressed Archive:\n    ```\n    tar czf files.tar.gz files\n    ```\n\n- Extract files from tar.gz\n    ```\n    tar xzf files.tar.gz\n    ```\n\u003cbr\u003e\n\n## Wild  cards\n- `*`, `?` are  wilcards\n\n- Use of wild cards:\n\n    - `ls *.txt` : list all files that ends with  .txt extension\n        - `*` implies any number of characters\n    \n    - To list all files that starts with \"file\" and succeeds by any one character and then \".txt\":\n    `ls file?.txt`\n    \n    - `ls file???.txt`\n        - `?` two characters\n        -  `???` means any 3 character\n    \n\n\u003cbr\u003e\n\n## sort command\n\n- to sort lines of  text files lexicographically\n\nExamples:\n\n- sort the lines  of file in alphabetical order:\n    ```\n    sort  [FILENAME]\n    ```\n\n- sort the lines of file in reverse order:\n    ```\n    sort -r [FILENAME]\n    ```\n\n- output the sorted file into a new file:\n    ```\n    sort  [FILENAME] \u003e [NEW-FILE]\n    ```\n\n- output the sorted lines of a file into a new file without duplicates:\n    ```\n    sort [FILENAME] \u003e uniq \u003e [NEW-FILE]\n    ```\n\n\u003cbr\u003e\n\n##  ln command\n- used to make links between files\n\n- `ln [FILE-NAME] [HARD-LINK]`: Create a hard link for a file (same inode)\n\n- `ln -s [FILE-NAME] [SOFT-LINK]`: Create a soft link for a file\n\n- `ln -s .. [SOFT-LINK]`: Create a soft link for the parent directory you are currently located in\n\n\u003cbr\u003e\n\n## grep  command\n- prints each line of a file that matches a pattern\n\nExamples:\n- list all directories present in the current  folder\n    ```\n    ls -l | grep ^d\n    ```\n    - `^d` : matches those lines that starts with letter 'd'\n\n    Output:\n    ![grep-cmd-output-1](images/grep-1.png)\n\n- Show the line numbers that matches the pattern \"hello\", ignoring case\n    ```\n    grep -i -n \"hello\" file.txt\n    ```\n    - `-n` : displays line number\n    - `-i` : ignores case\n\n- Ignore those lines that matches the pattern \"hello\"\n    ```\n    grep -v \"hello\" [FILENAME]\n    ```\n\n- To highlight words in a file or command output that ends with letter 'A':\n    ```\n    grep \"\\b\\w*A\\b\" [FILENAME]\n    ```\n    - `-b` : boundary\n    - `\\w*` : any number of characters\n-  Specifically display and highlight only those words that starts with letter 'A' or 'a':\n    ```\n    grep -o -i \"\\b\\A\\w*\\b\" [FILENAME]\n    ```\n    - `-o` : outputs only matching words\n    - `-i` : ignores case [ _NOTE: it works only when capital letter is used in the command to find the required search. ]_\n\u003cbr\u003e\n\n## CUT\n\n- used to extract characters or remove sections from each lines of files\n\nExamples:\n- To extract first three characters of every line:\n    ```\n    cut -c -3 [FILENAME]\n    ```\n- To extract characters starting from 2nd character of every line:\n    ```\n    cut -c 2- [FILENAME]\n    ```\n    \n- To extract last three characters of every line:\n    ```\n    cat [FILENAME] | rev | cut -c -3 | rev\n    ```\n- To display selected columns sorted by ID:\n    ```\n    cut -d $'\\t' -f1-4 movies.txt | sort -k1 -n\n    ```\n    - `$'\\t'` : tab space delimiter [taking columns seperated by TAB space]\n    - `-d`  : delimiter\n    - `-n`  : numeric value sorted\n    - `-f1-4` : columns 1 to 4\n    - `-k1` : sort by first column\n    - `-k2` : sort by second column\n\n\u003cbr\u003e\n\n## PASTE\n    \n- `paste [FILENAME-1] [FILENAME-2]` : concatenates two files. by default the delimiter is TAB\n- To explicity specify a delimiter/ concat file contents using delimiter:\n    ```\n    paste -d '-' [FILENAME-1] [FILENAME-2]\n    ```\n\u003cbr\u003e\n\n## User and Group handling\n### Switch user\n- `su root` : to go to the root account. '$' will change to '#'; su -\u003e switch user\n- `sudo su` : switching user\n\n### User Password\n- `passwd` : to change your login or root account  password.\n- `passwd [Account Name]` : to change password of that particular account.\n\n- `id [USER-NAME]` : shows user id; root account id is 0.\n\n### Create New User / Group \n- `sudo adddgroup [GROUP-NAME]`\n : to create new User Group\n- `sudo adduser [USERNAME]` : to create a new user account.\n- `sudo usermod -aG sudo [USERNAME]` : to make the user as a root user.\n\n### Remove User / Group\n- `sudo groupdel {GROUP-NAME}`\n : to remove a group:\n\n\u003cbr\u003e\n\n## Process management\n\n- `top`: list all processes and shows the cpu, memory usage and running background apps.\n- `ps aux` : lists all processes that are currently running in the device.\n    - `a` : --all Display information about other users' processes as well as your own.\n    - `u` : Display the processes belonging to the specified usernames.\n    - `x` : When displaying processes matched by other options, include processes which do not have a controlling terminal.\n- `kill [PID]` : kills or disables a process\n- `kill -9 [PID]` : stop a process\n\n\u003cbr\u003e\n\n## OS, CPU and Kernel information\n\n- `uname -a` : show kernel information\n- `xdpyinfo | grep 'dimensions:'` : to check screen resolution\nResult from above cmd:  dimensions:    1366x768 pixels (361x203 millimeters)\n\n- To check distro release version:\n    - `lsb_release -a` : provides certain LSB (Linux Standard Base) and distribution-specific information.\n    - `cat /etc/os-release`\n\n- `echo $XDG_CURRENT_DESKTOP` : to check Desktop Environment\n- `cat /proc/cpuinfo` : cpu information\n\n\u003cbr\u003e\n\n## Memory information\n- `df` : shows the disk space usage\n- `du` : shows directory space usage\n- `free` : shows memory and swap usage\n- `cat /proc/meminfo` : memory information\n\n\u003cbr\u003e\n\n## Path Locate\n- `pwd`   : shows the path of current working directory\n- `locate [SEARCH-NAME]` : to search files by name\n-  `whereis [APP/COMMAND]` : to locate binary file, manual page files of applications or commands\n- `which [APP/COMMAND]`: to locate a command or an application\n\n\u003cbr\u003e\n\n## Other useful commands\n- `man [COMMAND]` : shows the mannual page of the command\n- `history` : list all the cmds used (last 500 cmds)\n- `lsusb` : shows the USB buses and devices connected\n- `whatis [COMMAND]` : to give brief description or use of that command\n- `whoami` : checks whether you are root user/ whats the user name you are logged in as\n- `who` : display information about users who are currently logged in\n-  `w` : show who is logged on and what they are doing\n- `tty` : print the file name of the terminal connected to standard input\n- `!!` : executes the last command\n- `exit` : log out current session\n\n\u003cbr\u003e\n\n## Shortcuts\n- `CTRL + ALT + T`    : to open terminal [_NOTE: this may vary in distros, may not work for some_]\n- `CTRL + SHIFT + W`\n      or \n`CTRL + D`    : to close terminal\n- `CTRL + L`    : to clear the terminal\n- `CTRL + C`    : to terminate the program\n- `CTRL + D`    : TO log out of current session, similar to exit\n- `CTRL + Z`    : to pause/suspend the program\n- `CTRL + A`    : to go to start of the line/ command\n- `CTRL + E`    : to go to end of the line/ command\n- `CTRL + U`    : to clear the command\n- `CTRL + R`    : type to bring up a recent command\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderoyace%2Flinux-cmds","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderoyace%2Flinux-cmds","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderoyace%2Flinux-cmds/lists"}