Linux Cheat-Sheet
Linux Cheat-Sheet
Linux Cheat-Sheet
Neel Soni
Folders / Directory
Files
Merge 2 files and store data in one cat filename1 filename2 > filename3
Show only top lines from the file head –[number] [filename]
Show only bottom lines from the file tail –[number] [filename]
Find the difference between two files diff [options] <file 1> <file 2>
List out all the files and folders including hidden with file permissions ls -la
List out all the files and folders with file permissions ls -ltr
Print on screen
Clear Screen
ctrl + L (windows)
Make current line at the top of the screen without removing data
cmd + L (mac)
Copy all data starting with specific word/character cp <option> <source-location>* <destination location>
Delete
Remove the file and directory rm <option> <source location> <destination location>
<options>
-v verbose
-f for forcefully
History
Commands you have run till now history [options]
Super User
User Management
option:
Group Management
-d remove member
Edit file
change the group owner sudo chgrp <group name> <file name>
ACL
permission: r w x
Shell Scripting
Identify interpreter (first line for script) #!/bin/bash - GNU Bourne-Again Shell
./file.sh
bash file.sh
sh file.sh
Manage tools
xargs
build and execute commands from standard input xargs [options] [command]
Pattern:
$0 - entire line
Action:
option:
-name
-type
-user
-group
Search the file with less than 10 mb find /temp -size -10M
Search the file with more than 10 mb find /temp -size +10M
264
1755
Find a word in a file(s) grep [option] [expression] <file name> <file name> …
options:
-r = recursively
Search and redirect output in a new file grep [expression] <source file> > <destination file>
Disk space
-h Human readable
Archive
archives multiple files to TAR format tar [options] [archive_file] [file or directory to be archived]
-v Verbose output
-bz2 (compression)
-J (xz compression)
-C (specific destination)
File Size
User Manual
Job Automation
at > [expression]
eg. at 8:10 AM
ctrl+d
:wq
i. * - Minute field 0 to 59
ii. * - Minute field 0 to 59
iii. * - Day of Month 1-31
iv. * - Month field 1-12
v. * - Day Of Week 0-6
crontab [options]
-l jobs of current year
Show IP
ip addr
ip a
SSH
Remote connect any device with ssh sudo ssh [options] [username]@[ip address]
Services
Options:
enable - permanently on
stop - to stop
restart - to restart