{"id":25256523,"url":"https://github.com/estherslabbert/linux-and-bash-commands","last_synced_at":"2025-04-06T00:17:47.474Z","repository":{"id":185548553,"uuid":"673376386","full_name":"EstherSlabbert/Linux-and-Bash-Commands","owner":"EstherSlabbert","description":"Cheat sheet for Linux/Bash commands (can be used in writing scripts).","archived":false,"fork":false,"pushed_at":"2023-08-07T10:23:36.000Z","size":15,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-12T06:25:52.896Z","etag":null,"topics":["bash","cheatsheet","commands","linux-shell","scripting"],"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/EstherSlabbert.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}},"created_at":"2023-08-01T13:40:31.000Z","updated_at":"2023-08-02T08:59:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"15115744-368c-4503-a37a-fff1503b338c","html_url":"https://github.com/EstherSlabbert/Linux-and-Bash-Commands","commit_stats":null,"previous_names":["estherslabbert/bash_commands"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EstherSlabbert%2FLinux-and-Bash-Commands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EstherSlabbert%2FLinux-and-Bash-Commands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EstherSlabbert%2FLinux-and-Bash-Commands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EstherSlabbert%2FLinux-and-Bash-Commands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EstherSlabbert","download_url":"https://codeload.github.com/EstherSlabbert/Linux-and-Bash-Commands/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247416099,"owners_count":20935410,"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":["bash","cheatsheet","commands","linux-shell","scripting"],"created_at":"2025-02-12T06:20:12.429Z","updated_at":"2025-04-06T00:17:47.451Z","avatar_url":"https://github.com/EstherSlabbert.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bash Commands\n\n- `whoami`: lists the current user's username.\n- `date`: outputs current date and time system is running according to.\n- `clear`: clears the terminal so that you are able to type in a fresh terminal with unnecessary distractions from previous commands.\n- `ls`: lists visible files and folders in current directory.\n- `ls -a`: lists invisible files and folders in current directory.\n- `ls -l`: list permissions and associated files.\n- `cd` or `cd ~` or `cd ../..` or `cd /`: takes you to the home directory (`C:\\Users\\username` or `home/ubuntu` etc.). (change directory)\n- `cd C:/Users/username/folder1` or `cd ~/folder1`: takes you to the directory 'folder1' at the path `C:\\Users\\username\\folder1`.\n- `cd ..`: takes you back one folder.\n- `pwd`: outputs current location path. (print working directory)\n- `mkdir directory1`: makes a folder/directory called 'directory1' in the current location.\n- `touch file-name.txt`: modify file 'file-name.txt' or create file 'file-name.txt' if none exists.\n- `cat file-name.txt`: output contents of file called 'file-name.txt'. (concatenates and displays files)\n- `cat file-name.txt | head -n5` or `head -n5 file-name.txt`: display the first 5 lines of the file 'file-name.txt'. (Change number to be number of lines you want to select).\n- `cat file-name.txt | tail -n5` or `tail -n5 file-name.txt`: display the last 5 lines of the file 'file-name.txt'. (Change number to be number of lines you want to select).\n- `echo \"Any message you would like the terminal to output\"`: output a message to the terminal to be read.\n- `echo \"A message\" \u003e file-name.txt`: replace contents of 'file-name.txt' with the echoed message \"A message\".\n- `echo \"Additional message\" \u003e\u003e file-name.txt`: appends the echoed message \"Additional message\" to the 'file-name.txt' file.\n- `test -f file-name.txt \u0026\u0026 echo \"file exists\" || echo \"file does not exist\"`: check if a file exists in the current repository/directory.\n- `wc file-name.txt`: display the number of lines, words, and/or bytes of output.\n- `wc -m \u003c file-name.txt` or `cat file-name.txt | wc -m`: display the number of characters (includes new line characters) in the file 'file-name.txt' without the file name in the output.\n- `wc -m file-name.txt`: display the number of characters (includes new line characters) in the file 'file-name.txt' and the file name.\n- `wc -c \u003c file-name.txt`  or `cat file-name.txt | wc -c`: display the number of bytes in the file 'file-name.txt' without the file name in the output.\n- `wc -c file-name.txt`: display the number of bytes in the file 'file-name.txt'.\n- `wc -l file-name.txt`: display the number of lines in the file 'file-name.txt' and the file name.\n- `wc -l \u003c filename.txt` or `cat file-name.txt | wc -l` or `sed -n '$=' file-name.txt`: display the number of lines in the file 'file-name.txt' without the file name in the output.\n- `cat -n file-name.txt`: displays each line, ennumerated in the file 'file-name.txt' (e.g. where each /n is a new line in the output: /n1 First line. /n2 Second line. /n3 Third line).\n- `sed -n '=' file-name.txt`: displays numbers for each line in the file 'file-name.txt' (e.g. where each /n is a new line in the output: /n1 /n2 /n3).\n- `mv file1 file-name.txt`: renames 'file1' to be 'file-name.txt'. (Note that, if you use mv to give a file a name that already exists, it will cause that file to be overwritten)\n- `mv file-name.txt ~/folder/file-name.txt`: moves 'file-name.txt' to location '~/folder/file-name.txt'.\n- `rm file-name.txt`: removes file 'file-name.txt'.\n- `rm -r folder1`: removes directory and its contents. (Note: The -r option means \"remove files recursively\", i.e. it removes all files you specify, and if that file is a directory, it removes all files in that directory. If that directory has sub-directories of its own, it removes those, etc.)\n- `rm -r folder1/*`: removes all the contents of 'folder1' directory while still keeping the 'folder1' directory itself.\n- `rmdir folder1`: removes 'folder1' directory if empty.\n- `cp file1.txt file2.txt`: copies 'file1.txt' to another file called 'file2.txt'.\n- `diff file1.txt file2.txt`: shows differences between 'file1.txt' and 'file2.txt' or nothing if there are no differences.\n- `chmod u+x file-name.txt`: changes permissions of the file 'file-name.txt', giving the user executable permissions for the file. (Before `+` or `-` you can choose `u` for user, `g` for group, and or `o` for other to specify who the change is for (can leave blank or use `a` or `ugo` for all). after the `+` or `-` you can choose `w` for write, `r` for read and or `x` for execute permissions. The `+` gives the permission(s) and the `-` removes the permission(s).)\n- `ps`: gives a list of processes running and their process IDs.\n- `kill process-id`: kills a process if you replace `process-id` with the actual process ID (PID).\n- `variable_name=variable_value`: sets a variable called `variable_name` to be the value `valriable_value`, and can be called on using `echo $variable_name` or `echo ${variable_name}` when working with multiple variables or punctuation. (Note: variables are case-sensitive, connot contain spaces or special characters except `_` and it must start with a letter. If you want things to be as they are without using an escape character then use `'` `'`)\n- `env` or `printenv`: lists all environment variables.\n- `printenv ENV_VAR` or `echo $ENV_VAR`: returns the value of the environment variable 'ENV_VAR'.\n- `grep \"part-of-word-or-sentence\" ./path/to/file-name.txt`: searches for and returns the line that contains \"part-of-word-or-sentence\" in './path/to/file-name.txt'. (using `-i` with grep makes its search case-insensitive, `-i \"^ip\"` will search for lines that start with 'ip', `-i \"ip$\"` will search for lines ending in 'ip', `-iv` will exclude the lines containing whatever is specified.)\n- `grep -q \"part-of-word-or-sentence\" file-name.txt`: runs grep command in quiet mode, so it returns no output.\n- `echo $?`: gets error or run code (usually between 1-155) for last command (0 if successful).\n\nFor additional information: [Charmm gui Unix lessons](https://charmm-gui.org/?doc=lecture\u0026module=unix\u0026lesson=1)\n\n## Additional useful things to know\n\n`\\` is an escape character. (Example use case: So if you have a file name and have not placed it in quotation marks that has a space you can use the escape character before the space to make sure the file name is correctly referenced. - can be used for other special characters that are not meant to perform a function)\n\n`|` is a pipe operator and is used to connect commands together (form more specific or complex commands).\n\nUsing `sudo` before a command elevates the command to have admin privileges.\n\nOn Ubuntu systems environment variables are stored in the `.bashrc` file located at `~/.bashrc`.\n\nIf using [`vi`](https://www.redhat.com/sysadmin/introduction-vi-editor) the commands are different.\n\nSee [`nano`](https://www.hostinger.co.uk/tutorials/how-to-install-and-use-nano-text-editor) commands for additional file writing and [`sed`](https://www.geeksforgeeks.org/sed-command-in-linux-unix-with-examples/) commands for editing files without even opening them.\n\n[`cURL`](https://blog.hubspot.com/website/curl-command#:~:text=Client%20URL%20) commands receive the URL to transfer data to — or receive data from — along with other options for different purposes (often seen when installing specific versions of software).\n\nThe [`time`](https://www.hostinger.co.uk/tutorials/linux-time-command/) command can be used to see how long it takes to execute a certain command and usually follows the format `time command` (where `command` is an actual command).\n\n[`cron`](https://opensource.com/article/21/7/cron-linux#:~:text=The%20cron%20system%20is%20a,run%20commands%20on%20a%20schedule.\u0026text=30%20readers%20like%20this.\u0026text=SA%20Seth%20Kenlon-,The%20cron%20system%20is%20a%20method%20to%20automatically%20run%20commands,a%20file%20called%20a%20crontab.) commands are to deal with scheduled jobs.\n\nTo securely log in to a remote machine and execute commands use `ssh user@host` (basic syntax).\n\n`#!/bin/bash` is the line necessary at the start of a shell script file. (`#!` is known as a shebang)\n\n`*` is a wild card character, meaning it is used as a placeholder to signify all or everthing (often used with file extensions e.g. `*.txt` means all .txt files in the location specified).\n\n`\u0026\u0026` is used to run 2 commands from one line (e.g. `sudo apt-get update -y \u0026\u0026 sudo apt-get upgrade -y` gets updates and upgrades on linux).\n\n`Ctrl` + `C` cancels a process or logs you out.\n\n`exit` will end a terminal session or log you out if logged in to a remote session.\n\n`Ctrl` + `Z` suspends a process. `bg` moves the suspended process to the background. `fg` moves the process to the foreground.\n\n`Ctrl` + `D` logs you out of an interface.\n\n`Ctrl` + `Ins` copies the selected characters from the Bash terminal and `Shift` + `Ins` pastes into a Bash terminal.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Festherslabbert%2Flinux-and-bash-commands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Festherslabbert%2Flinux-and-bash-commands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Festherslabbert%2Flinux-and-bash-commands/lists"}