Command Line and Terminal navigation Cheat Sheet by Kyngo (Kyngo) via cheatography.com/131267/cs/26366/
Basics Basics (cont) Basics (cont) cd [path] change your current directory rm [file] removes a file less [file] prints a file using pagination
to the specified one rm -rf removes a folder and all of its more [file] same as less [file] cd ~ go to your home folder [file] contents ln -s makes a symbolic link of a cd - go the the folder you were cat [file] prints a file's contents [source] given source at the given before tac [file] prints a file's contents from [desti‐ destina tion ls list the contents of the bottom to top nation] directory sed allows replacing of contents in cal prints a calendar on the ls -lh list the contents of the files with regular express ions terminal directory in a human-f rie ndly grep prints the contents of a given date reports the current date and format [pattern] file that match the given pattern time cp [origin] copies the given file wherever [file] Write (or append to) a file without an [desti‐ you want to tr -s replaces all concurrent editor nation] [pattern] duplicates of a given pattern mv [origin] moves or renames the given tr replaces the given pattern with cat > [file] << EOF [desti‐ file [pattern] the given replace ment string hello world nation] [repla‐ this is a file's content pwd get the current directory you're cement] blah blah blah in tr -d removes the given pattern from hello again mkdir create a folder [pattern] a string bye for now EOF [name] head prints the first lines of a given mkdir -p create a folder and all its [file] file In order to append to a file instead of [name] parents, if needed tail [file] prints the last lines of a given replacing all of its contents, add two output chmod change a file's permiss ions - file cones instead of only one (>>). 755 Allows the user to read, write cut -f allows you to print specific Command pipeline concate nation [name] and execute, and anyone else [field] -d fields from an origin that have a example to just read and execute [separ‐ given separator chmod change a file's permiss ions - ator] curl https:/ /de vel ope r.an dr oi‐ 400 Only the owner will be able to uname gets the OS kernel's name d.com/studio#downloads | grep [name] read the file (Linux, Darwin...) ".dmg " | grep href | head -n1 | cut -f2 -d"=" | tr -d '"' chown changes the owners of a given uname - gets the machine's archite cture This command will: user:group file or folder m (if not within an emulator) [name] - download the downlaods page for Android uname -r gets the kernel version Studio chown -R changes the owners of a given uname - shows all the details of your - find for the lines that contain ".dmg " within user:group file or folder, and all of its a UNIX OS them [name] contents - filter again to get only those that contain "‐ touch creates a file with the given href " [name] name - filter again to get only the first occurrence file [name] reports the file type - split the result to get only the second field using = as a separator - remove any double quotation marks on the string
By Kyngo (Kyngo) Published 29th January, 2021. Sponsored by Readable.com cheatography.com/kyngo/ Last updated 4th May, 2021. Measure your website readability! arnaumart.in Page 1 of 4. https://readable.com Command Line and Terminal navigation Cheat Sheet by Kyngo (Kyngo) via cheatography.com/131267/cs/26366/
Command pipeline concate nation Networks Pipelines and operators (cont) example (cont) ifconfig Shows a general network brief [command] appends a file's contents
The result should be a link that, when ip addr Same as ifconfig but on << [file] into the program opened, will download the macOS installer show Linux [command1] if command1 succeeds, for Android Studio. nmap Scans the ports of the given IP && command2 will be executed Please note, if the website changes, this [ip]/32 [command2] command may not work as is. ping Send a sequence of ICMP [command1] if command1 fails, || command2 will be executed Manuals [host] packets to a host [command2] whois Tells you informa tion about the Almost all programs on any Unix OS will [host] domain & the process will be run in the have what's called a "m anp age ". This is an background instruc tion manual with details on how to dig Tells you how a specific !! the last executed command use a program. [domain] domain resolves In order to read the manual for a specific nslookup The same as dig [domain] $? the last command's exit applica tion, just type man [applic ati on] [domain] code and you will be able to read how it works. host Reports several types of [command1] sends the output of Press "Q " to close the manual when you're [domain] records for a given domain | command1 to command2's done. [command2] input wget [url] Downloads the given URL to -O [file] the specified file [command] \ allows you to make a line sed examples break without executing the curl [url] - Downloads the given URL to The sed command uses a string as command o [file] the specified file parameter to determine what to oeprate, [command] redirects the command's iftop Allows you to monitor the and can receive several more parameters to 2>&1 stderr to stdout network throughput (Linux) configure the behavior. `[com‐ runs the given command, netstat - Shows which applica tions are sed -i 's/hell o/hi/' file.txt will mand]` and then runs the result as a tulpn using what ports (Linux) replace the first instance of "h ell o" that the command itself script can find at each line, and write the sudo lsof Shows which applica tions are result at the same given file. To avoid -i -n -P using what ports (macOS) Remote hosts overwri ting, you can just remove the -i ssh [server] connects to a server via argument. Pipelines and operators SSH sed -i 's/hell o/h i/g' file.txt [command] outputs the result of a ssh [server] -p [port] will replace every instance of "h ell o" that > [file] command to a file exist in the file. ssh [server] -i [certif icate] [command] outputs the result of a To apply the patterns from a file, use the - >> [file] command to the end of a file scp [user]@[s‐ copies a file from a fpar ameter with a path to a file. erve r]: [path] remote server to your [command] gets a file and prints its If you want to make a backup of the file, add [local path] machine < [file] content as if it were you a suffix for said file after the -i parameter. entering it telnet [host] makes a raw tcp For example: [port] connection to a given sed -i".bk p" 's/hell o/h i/g' host and port file.txt will generate a file named w reports who's file.tx t.bkp with the original contents. connected at the Regular express ions can be applied to the machine pattern given to sed, as maybe you want to who same as w replace something that may not be an exact string, but rather a pattern of it.
By Kyngo (Kyngo) Published 29th January, 2021. Sponsored by Readable.com cheatography.com/kyngo/ Last updated 4th May, 2021. Measure your website readability! arnaumart.in Page 2 of 4. https://readable.com Command Line and Terminal navigation Cheat Sheet by Kyngo (Kyngo) via cheatography.com/131267/cs/26366/
Remote hosts (cont) Loops and decision taking (cont) Package Managers (cont) whoami tells you your username done choco Windows (Chocol atey) For SCP, you can upload from your "If-else if-else" operator Searching machine to a remote server by changing the if [ $UID -eq 0 ] order of the commands. You can also use then find [path] finds anything within a given SSH's parameters with SCP (for port, you echo You are root -name path with a given pattern on must use -P (capita l)). elif [ $UID -eq 1 ] [name its name echo You are user with ID 1 pattern] Environ ment variables else whereis tells you all the locations for a echo You are NOT root PATH the directo ries where the shell [name] given binary name fi will find for the command which tells you the given binary binaries [name] name's path that will be run Permission bits HOME your home directory according to your PATH 0 --- Do nothing UID the user ID locate tells you the location of any 1 --x Execution [name] kind of file within your EUID the user ID running the machine command 2 -w- Write
SHELL your current shell 3 -wx Execute and write Monitoring the OS PS1 your prompt's style 4 r-- Read ps prints a snapshot of all system 5 r-x Read and execute PWD your current directory aux processes 6 rw- Read and write RANDOM random number top shows the processes running on HOST the host's name 7 rwx Read, write and execute the machine LANG the shell's language Here "r " stand for "r ead ", "w " stands for "‐ htop shows the processes running on TTY your current session's TTY writ e", and "x " stands for "e xec ute ". It may the machine with some graphs for be useless to have permiss ions below 4, as memory usage Loops and decision taking you won't be able to read the file. A 0 df -h prints the system's storage devices' permission is useful to fully restrict access "F or" loop usage to any other user. for i in {1..10} du - prints a folder or file size do hs Permiss ions are usually represe nted by echo $i [path] three digits, and their meaning is the done following: the first one represents the owner free - reports used and free ram and "W hil e" loop (example of an infinite loop) user of the file, the second number m swap while [ true ] represents the owner group's permiss ions, kill kills a process with the given pid do and the last one represents everybody [pid] echo hello else's permiss ions. kill -9 forcefully kills a process with the done [pid] given pid "U nti l" loop (do while) Package Managers until [ $IDX -eq 5 ] apt Debian, Ubuntu do yum Amazon Linux, Red Hat echo $IDX dnf Red Hat, Fedora ((IDX+ +)) pacman Arch Linux emerge Gentoo
brew macOS (Homebrew)
By Kyngo (Kyngo) Published 29th January, 2021. Sponsored by Readable.com cheatography.com/kyngo/ Last updated 4th May, 2021. Measure your website readability! arnaumart.in Page 3 of 4. https://readable.com Command Line and Terminal navigation Cheat Sheet by Kyngo (Kyngo) via cheatography.com/131267/cs/26366/
Monitoring the OS (cont) ls parameters (cont) Niceness (cont) kill -l lists the termina tion codes -m list with commas instead of tabs renice 19 [pid] will make the process available to send the processes -t sort by newest to oldest with given PID have the least priority within pkill kills any processes with the the CPU. This means that, when the OS is [process name provided (also works with grep parameters running low on CPU resources, this process name] -9 and other numeric signals) will be more ignored than one with a lower -i case insensi tive niceness number. xkill kills a graphical process (Xorg) -v hide all matches renice -20 [pid] will make this lsblk lists the drives, its partiti ons, and -r recursive search process have the most CPU availab ility space (Linux) -e regular expression pattern even when resources are scarce. blkid shows the mount details of each -x match entire line volume (Linux) S3 Commands (aws s3) -w match entire word lspci lists PCI devices ls s3://bu cke t/‐ Lets you know if -f [file] use patterns from file lsusb lists USB devices file a file exists or not -I do not search inside binary files cp s3://bu ck‐ Downloads a file Compres sion -R recursive, even with symlinks et/file /path/‐ into your tar xf [file] extracts a tar file at the current on/m ach ine computer screen parameters path cp --recur sive Downloads a tar cf creates a tar file with the given screen creates a new screen session s3://bu cke t/‐ folder and its [filename] name from the given content screen - lists the existing screen folder /path/o n/‐ content into your [content] ls sessions mach ine computer tar zcf creates a gzipped tar file with screen -r resume a given screen rm s3://bu cke t/‐ Removes a [filename] the given name from the given [name] file remote file [content] content CTRL + activates commands for the All commands must begin by aws s3. unzip [file] unzips a .zip file A active screen session Paths can be specified in both ways: from zip creates a .zip file with the CTRL + disconn ects from the screen local to remote, or from remote to local. [filename] given name from the given A, D They can also work from remote to remote, [content] content but will use your device as a bridge. sort parameters ls parameters -n numeric -l detailed list -r reverse -h human-r ead able file size, used with -l -k [number] specific field -r reversed -f case insensi tive -d list directo ries themselves ls -l | sort -n -k5 will list a folder's -a include dotfiles (hidden files) contents by its size, from the least to the --si list using base 1000 instead of 1024 most sized.
Niceness
Niceness is they way Unix OSes give priority to the applica tions running on the machine. A niceness of 19 means it's got the least priority, whereas a -20 priority means it's got the most priority.
By Kyngo (Kyngo) Published 29th January, 2021. Sponsored by Readable.com cheatography.com/kyngo/ Last updated 4th May, 2021. Measure your website readability! arnaumart.in Page 4 of 4. https://readable.com