Command Line Cheatsheet PDF

Document Details

Uploaded by Deleted User

Tags

command line linux commands terminal commands computer science

Summary

This document provides a cheatsheet for common Linux command-line commands and concepts, including file manipulation, process control, and networking protocols. It includes examples for commands like pwd, ls, cd, mkdir, and grep, and details concerning networking protocols like TCP/IP.

Full Transcript

pwd: print the current working directory cd: change directories o cd.. move up one directory level. o cd - return to the previous directory. o cd ~ go to the home directory. ls: list the contents of a directory o ls -l list all details o ls -a...

pwd: print the current working directory cd: change directories o cd.. move up one directory level. o cd - return to the previous directory. o cd ~ go to the home directory. ls: list the contents of a directory o ls -l list all details o ls -a list all files, including files which are normally hidden o ls -F distinguish between directories and regular files o ls -R display everything under a directory mkdir: create a directory rmdir: delete a directory rm: delete files or directories o -r recursively remove directories and their contents mv: move a file or rename a file cp: copy a file, leaving the original intact o -r recursively copy directories cat: display the entire contents of a file at once o -n display with line numbers less: display the contents of a file one screen at a time o :q quit the viewer o :n next file o :p previous file head: display the beginning of a file o -n N show the first N lines tail: display the end of a file o -n N show the last N lines cut: extract fields(columns) o -f [fields] specify fields to extract (delimited by a character) o -d [delimiter] specify the delimiter (default is tab) grep: search for lines in a file that match a specified pattern o -c print a count of matching lines rather than the lines themselves o -h do not print the names of files when searching multiple files o -i ignore case (e.g., treat "Regression" and "regression" as matches) o -l print the names of files that contain matches, not the matches o -n print line numbers for matching lines o -v invert the match, i.e., only show lines that don't match man: show the manual or help page for a command history: display a list of previously executed commands o !N execute a command from the history by its number N o !! execute the most recent command from history sort: sort lines of text in a file or input o -r reverse the order o -n sort numerically uniq: remove duplicate consecutive lines o -d show only duplicate lines o -u show only unique lines o -c counts the occurrences of each unique line wc: count lines, words, and characters in a file o -c count characters o -w count words o -l count lines redirections: command < in_file > out_file 2> err_file o > redirect output to a file, overwriting it o >> redirect output to a file, appending to it o 2> redirect errors to a file, overwriting it o < redirect input from a file piping: commandA | commandB | commandC o | pass the output of one command as input to another command wildcards: match filenames and text patterns o * match zero or more characters o ? match exactly one character o [set] match any one character in the set o {…} match any of the comma-separated patterns inside the curly brackets ssh: connect to a remote server via SSH chmod: change file permissions sudo: execute a command with superuser privileges nano: open a file in the Nano text editor scp: securely copy files between hosts Network protocols  The Internet’s main protocol suite (as defined by the document RFC1122) is collectively known as the TCP/IP stack. The TCP/IP stack organizes protocols into the following layers:  Application Layer (user-user communication; close to business logic)  Transport Layer (process-process communication with reliable data transfer)  Internet Layer (host-host communication across boundaries of networks)  Link Layer (machine-machine communication, close to hardware)  Examples:  HTTP and HTTPS protocols that deliver web pages between users belong to the Application Layer. This means these protocols do not have to be concerned with how data is being transmitted.  IEEE802.11, known as WiFi, or wireless Ethernet, exists within the Link Layer. It is responsible for controlling physical hardware, but it is not concerned with the type of content that can travel within its data units. Application Layer protocols based on the Client-Server Model Application Layer protocols are concerned with facilitating communication between users and delivering a certain user-oriented value. Application Layer protocols are implemented directly by application software. Transport Layer protocols Transport Layer protocols are concerned with facilitating communication between processes for the purpose of offering reliable data transfer. There are two main protocols offering Transport Layer services implemented by operating systems:  TCP (Transmission Control Protocol)  UDP (User Datagram Protocol) Internet Layer protocols Internet Layer protocols are concerned with facilitating communication between computers that may be connected to the same network (intra-network communication), or to two different networks (inter-network communication) capable of exchanging data. Internet Layer protocols must be implemented by operating systems of hosts, as well as every single router between them for hosts to communicate successfully. A router is a device that belongs to multiple networks and – based on preconfigured rules, or dynamic routing protocols – forwards (copies) data incoming from one network to another network. Link Layer protocols Link Layer protocols are concerned with facilitating communication between computers that are connected to the same medium (e.g. cable, fiberoptic wire, electromagnetic air gap). Two devices communicating directly in the Link Layer are considered to exist in the same network. Application software is unaware which Link Layer protocol is used to deliver its data. Commonly used link layer protocols:  IEEE 802.3 (wired Ethernet)  IEEE 802.11 (wireless Ethernet; WiFi)  SONET/SDH (fiberoptic communication)  4G, 5G (Cellular)  PPP (Point-to-Point protocol for direct router-to-router communication)

Use Quizgecko on...
Browser
Browser