Skip to content

mcormack/linux-command-reference

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

20 Commits
ย 
ย 

Repository files navigation

linux-command-reference

Linx Mascot - Tux

All Commands and Shortcuts:

Reference for Linux Commands

  • ๐Ÿ–‹๏ธ 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 another cp [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 file2 Options
  • ๐Ÿ•ธ๏ธ 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

๐ŸŽฅ Good References / Sources

  1. ๐Ÿ“ผ TechWorld with Nana - 13 Linux Commands: Mentioned Commands:
    • uname, pwd, cd, ls, cat, grep, cp, wc, find, diff, curl, vim, chmod
  2. ๐Ÿ“‹ Linux Commands Cheat Sheet
  3. ๏นฅ Other CLI Tools 10 CLI apps Video

๐Ÿ“‹ Extended Reference - Commands' Options

uname

  • -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

ls

Most Used

  • -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.

Others

  • -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

cat

  • -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

grep

  • 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

โฌ† GO UP

cp

Examples

Simple Copy

cp file1.txt file1_copy.txt

Copy to another Directory, passing the direct path:

cp file1.txt /root/file1_copy.txt

Also 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

wc

  • -l Count Lines
  • -w Count Words
  • -c Bytes
  • -m Characters
  • -L find longest Line Length

โฌ† GO UP

find

  • 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 +1M

More info: Linux Manual on Find

โฌ† GO UP

diff

  • -c: Display the differences in a more readable format.
  • -w: Ignore white space differences.

โฌ† GO UP

curl

  • -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

vim

  • 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.config

Navigation:

  • To enter edit mode, press i.
  • To Exit: Press ESC (Back to normal mode) then ":" and:
    • :q Quit only if no changes have been made.
    • :q! Quit without Saving
    • :w Save the file
    • :wq or ZZ
    • x Save and quit only if changes were made.

โฌ† GO UP

chmod

  • File Permissions

    • Initial symbol: - File, d Directory, l Sybolic 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
## 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

touch

  • -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

Other

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 Database

Output functions result into a textfile using >:

## Output result to a file
cat file1.txt | grep Database > filtered.txt

Append 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

Useful Tools

  1. ๐Ÿ› ๏ธ It Tools -> Web Version -> Forked due to non maintenance -> Next Tools -> Web Version

About

Reference for Linux Commands

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published