Linux: basic command
1. Shell basics
| Command | What it does |
|---|---|
chsh | Change your login shell (prompts if no shell is given) |
pwd | Print current working directory |
file <name> | Identify the type of a file |
less <file> | Page through a file (q to quit, / to search) |
head -n N / tail -n N | Show first / last N lines |
grep -i -v | Search text: -i ignore case, -v invert match |
diff a b | Show differences between two files |
find <dir> -name <file> -print | Search directory tree by name |
locate <name> | Fast search using a prebuilt index |
man -k <keyword> | Search manual pages by keyword |
passwd | Change your password |
Environment variables
VARIABLE=value # shell variable (current shell only)
export VARIABLE # make it an environment variable (visible to child processes)
$PATH — colon-separated list of directories the shell searches when locating a command.
2. Special symbols
| Symbol | Name | Meaning in Linux |
|---|---|---|
Esc | Escape | Leaves modes (e.g. insert mode in vi/vim) |
~ | Tilde | Home directory: cd ~ |
` | Backtick | Command substitution (old style): `date` |
! | Bang | History: !! last command, !$ its last argument |
@ | At | user@hostname in prompts and SSH |
# | Hash | Comment marker; root’s prompt symbol |
$ | Dollar | Variables ($HOME, $1); regular user’s prompt |
% | Percent | Job control (%1); modulo in arithmetic |
^ | Caret | Start of line in regex: grep '^root' /etc/passwd |
& | Ampersand | Run in background: ./script.sh & |
* | Star | Wildcard, matches anything: rm *.log (dangerous!) |
( ) | Parentheses | Grouping / subshells |
_ | Underscore | No special meaning — safe in filenames |
- | Dash | Command options: ls -l |
{ } | Curly braces | Brace expansion: mkdir dir{1,2,3} |
[ ] | Square brackets | Character sets (file[12]); test conditions in scripts |
: | Colon | vi commands (:wq); separator in $PATH, /etc/passwd |
; | Semicolon | Chain commands: cd /tmp; ls |
" " | Double quotes | One argument, variables still expand |
' ' | Single quotes | One argument, nothing expands |
| | Pipe | Send output of one command to input of another |
\ | Backslash | Escape next character (Windows path separator, not Linux) |
< | Less-than | Input redirection |
> | Greater-than | Output redirection (overwrites) |
>> | Double greater-than | Output redirection (appends) |
. .. | Dot, dot-dot | Current / parent directory; leading dot hides a file |
? | Question mark | Wildcard for exactly one character: file?.txt |
/ | Forward slash | Path separator and filesystem root |
3. Redirection and pipes
File descriptors: 0 = stdin, 1 = stdout, 2 = stderr.
cmd > file # stdout to file (overwrite)
cmd >> file # stdout to file (append)
cmd 2> file # stderr to file
cmd > file 2>&1 # stdout and stderr to the same file
cmd < file # file as stdin
cmd1 | cmd2 # stdout of cmd1 -> stdin of cmd2
4. Processes
ps x # all your processes
ps ax # all processes on the system
ps u # more detailed information
ps w # full command names
ps u $$ # info about the current shell ($$ = its PID)
| Command | Effect |
|---|---|
kill <pid> | Terminate (TERM) |
kill -STOP <pid> | Freeze |
kill -CONT <pid> | Resume |
kill -KILL <pid> | Force kill (last resort) |
kill -l | List signal numbers and names |
jobs | Show suspended / background jobs |
cmd & | Run command in background |
nohup cmd & | Keep running after logout |
5. File permissions
-rw-r--r-- 1 linuxize users 12288 Apr 8 20:51 filename.txt
|[-][-][-]- [------] [---]
| | | | | | |
| | | | | | +------------> 7. Group
| | | | | +--------------------> 6. Owner
| | | | +--------------------------> 5. Alternate access method
| | | +----------------------------> 4. Others permissions
| | +-------------------------------> 3. Group permissions
| +----------------------------------> 2. Owner permissions
+------------------------------------> 1. File type
File type: - regular file, d directory, l symbolic link.
chmod — numeric values
| Permission | Value |
|---|---|
r read | 4 |
w write | 2 |
x execute | 1 |
| none | 0 |
Example 754: owner rwx = 7, group r-x = 5, others r-- = 4.
umask— default permissions mask for newly created filesln -s <target> <linkname>— create a symbolic link
6. Archives and compression
gzip file # -> file.gz
gunzip file.gz
zcat file.gz # same as gunzip -dc (print to stdout)
tar cvf archive.tar file1 file2 # create
tar xvf archive.tar # extract
tar tvf archive.tar # list contents
tar ztvf file.tar.gz # list a gzipped archive
| Flag | Meaning |
|---|---|
c | create |
x | extract |
t | test / list |
v | verbose |
f | next argument is the file |
p | preserve permissions |
z | gzip compression |
7. Filesystem Hierarchy Standard
/
├── bin/ ready-to-run commands (essential binaries)
├── sbin/ system executables (for root)
├── boot/ kernel and boot loader files
├── dev/ device files
├── etc/ core system configuration (passwd, boot, network, ...)
├── home/ personal directories of regular users
├── lib/ shared and static libraries used by executables
├── media/ mount point for removable media (USB drives, ...)
├── opt/ additional third-party software
├── proc/ info about running processes and kernel parameters
├── run/ runtime data: PIDs, sockets, status records, logging
├── sys/ device and system interface (similar to /proc)
├── tmp/ small temporary files
├── var/ variable data: logs, caches, user tracking
└── usr/ user programs and data
├── include/ header files for the C compiler
├── local/ software installed by the administrator
├── man/ manual pages
└── share/ architecture-independent files
Kernel location: /vmlinuz or /boot/vmlinuz.
8. Root and sudo
sudo <cmd> # run command as root
visudo # safely edit /etc/sudoers (who may use sudo)
journalctl SYSLOG_IDENTIFIER=sudo # view sudo logs