- ๐๏ธ
uname: Print basic info about system OS and hardware. Options - ๐
pwd: Print working directory, where are we located. - ๐
cd: Change working directory. - ๐
ls: Lists / displays contents of a directory. Shows files and directories within the current directory. Options - ๐โโฌ
cat: Concatenate: Read the contents of any file. Options - ๐
grep: General Regular Expression Print: Search for text patterns in files or output. Filters and displays lines that match a specific string or patttern. Options - ๐ฎ
cp: Copy files from one directory to anothercp [SOURCE] [DESTINATION]Options - ๐ฏ
wc: Word Count: Count number of lines, words, characters in a file or some input. Options - ๐
find: Search for Files and direcories.find [starting_path] [option] [expression]. Options - ๐ฆ
diff: Compare two files and show the difference.diff file1 file2Options - ๐ธ๏ธ
curl: Client URL. Used to transfer data from or to a server using HTTP or other protocols. Typically used to interact with APIs. Options - ๐
vim: Open VIM Editor to change files. Options - โ๏ธ
chmod: Change Mode: Modify file permissions. Options - โ
touch: Create files or update the timestamps.touch [options] [file_name(s)]Options
- ๐ผ TechWorld with Nana - 13 Linux Commands: Mentioned Commands:
- uname, pwd, cd, ls, cat, grep, cp, wc, find, diff, curl, vim, chmod
- ๐ Linux Commands Cheat Sheet
- ๏นฅ Other CLI Tools 10 CLI apps Video
- -a All System Information
- -s Kernel name (default)
- -r Kernel release
- -v Kernel version
- -m Machine hardware architecture / name (ex., x86_64)
- -n Network hostname
- -o Operating system
- -p Processor type
โฌ GO UP
- -l Long format: Shows files details: permisions, owner, size and modification date.
- -h Displays file sizes in human-readable formats (e.g., KB, MB) when combined with -l.
- -t Sorts files by modification time, with the newest first.
- -a All files, including hidden ones.
- -R Lists contents of directories recursively, including subdirectories.
- -r Reverses the order of the output.
- -1 Lists one file per line instead of displaying them in columns.
- -d Lists directories only.
- -F Appends a character to filenames indicating their type (e.g., / for directories, * for executables).
- -X Sorts files alphabetically by their extension.
โฌ GO UP
- -n: Displays the output with line numbers.
- -E: Displays a $ character at the end of each line.
- -s: Squeezes multiple adjacent empty lines into one.
You can join multiple files into a new file:
cat file1.txt file2.txt > merged.txtโฌ GO UP
- Searching within a specific file:
grep dog sample.txt- When searching for phrases use "":
grep "connection refused" sample.txt- -i makes the search case-insensitive.
- -c display the count of matches.
- Use regex for more advanced seach patterns. Lines that start with Hello for example:
grep "^Hello" -i sample.txt- More complex search examples ๐๏ธ Search Patterns Examples
โฌ GO UP
Simple Copy
cp file1.txt file1_copy.txtCopy to another Directory, passing the direct path:
cp file1.txt /root/file1_copy.txtAlso used to copy directories:
cp -r dir1 dir2- -r used to copy directories recursively, including internal files.
- -p preserve the original file attributes and timestamps
โฌ GO UP
- -l Count Lines
- -w Count Words
- -c Bytes
- -m Characters
- -L find longest Line Length
โฌ GO UP
- Options: You can search by name, file type, file size or permission.
- -type: f file, d directory.
- -size: Finding by size, using + and - prefixes signifying greater than and less than. 'M' for mebibytes, 'G' for gibibytes, 'k' for kibibytes.
- Examples: "."= Current Directory. "/"= Entire File System. Root file system.
find -name / "*.conf"
# Combine with grep to filter:
find -name / "*.conf" | grep db
find -name / "*.conf*" | grep db
# Larger files:
find . -size +1MMore info: Linux Manual on Find
โฌ GO UP
- -c: Display the differences in a more readable format.
- -w: Ignore white space differences.
โฌ GO UP
- -I (or --head): Just return the headers. (Metadata)
- -O Tells curl to save the file with the same name as the remote file.
- -o To specify a different file name.
curl https://google.com
curl http://localhost:5432
curl -o curl_homepage.html https://google.comโฌ GO UP
- Commonly used for editing config files in Linux
- It has 3 modes
- Insert Mode: type or edit text.
- Normal Mode: Default, for navigation
- Command Mode: Execute commands like save, quit, search.
vim db.configNavigation:
- To enter edit mode, press i.
- To Exit: Press ESC (Back to normal mode) then ":" and:
:qQuit only if no changes have been made.:q!Quit without Saving:wSave the file:wqorZZxSave and quit only if changes were made.
โฌ GO UP
-
File Permissions
- Initial symbol:
-File,dDirectory,lSybolic Link - Different types:
-rwxrwxrwx: Read, Write, Execute,-is denied. - Position is in this order: User, Group, Other. so
-rw-rw---means User and Group can only read and write. - To change permissons each permission has a numeric value: r=4, w=2, x=1
- Initial symbol:
## Full Permissions
chmod 777 db.config
## No Permissions
chmod 000 db.config
## Read Permissions only for all groups
chmod 444 db.config
## Owner rwx, Group and Others: rx (Good for Scripts)
chmod 755 db.config
## Owner rw, Group and Others: r (Usually Text files)
chmod 644 db.configโฌ GO UP
- -a: Updates the access time of the file.
- -m: Updates the modification time of the file.
- -d or -t: Sets the access and modification times to the specified date and time.
- -c or -f: Creates the file if it doesn't exist, without issuing an error message.
touch new_file.txtโฌ GO UP
Chain multiple commands using the | (pipe) operator. Whatever the first command outputs it will be the input of the following command.
## Chain Commands
cat file1.txt | grep DatabaseOutput functions result into a textfile using >:
## Output result to a file
cat file1.txt | grep Database > filtered.txtAppend lines to .txt using >.
## Create sample text files
echo "First line of file_1.txt." > file_1.txt
echo "Second line of file_1.txt." >> file_1.txtโฌ GO UP
- ๐ ๏ธ It Tools -> Web Version -> Forked due to non maintenance -> Next Tools -> Web Version