Linux Commands
1) ssh - First open the ubuntu terminal
Use nano for creating file
Example- nano example1.pem and hit enter
Now copy the pem file data and paste it in nano example1.pem file
Now type chmod 400 sample1.pem Hit enter
Now type this
ssh -i "sample1.pem"
[email protected]Ssh is a protocol
-i is an identifier
Example1.pem is a key
Ubuntu is uername
Ec2-3-87-30-245.compute-1.amazonaws.com is a DNS server
2) pwd : It prints current working directory
● pwd -P It prints the parent working directory
3) whoami : It displays username of current user
4) mkdir <directory> : It creates directory
● mkdir -p <directory> : It make parent directories also if it does not exist
5) cd
● cd .. : change to parent directory
● cd - : change to previous directory
● cd <directory name> : change to other directory where you want to go
● cd ~ change to home directory
● cd : change to home directory
6) ls list content
● ls -l : list content in long listing format
● ls -al : list all sub content in long listing forma
● ls -ltr - sorts chronologically from older to newer (bottom)
● ls -R : list content recursively
● ls -F : list content and classify them
7) man <cmd> - Shows the manual of command Eg: man cat
8) alias display all aliases for current user
● alias <statement> make alias eg alias c='clear'
● unalias <alias> remove alias eg unalias c
9) touch test.txt - will create a zero-byte file, if it doesn't exist
● touch -t 200801091530 123456.txt - changes timestamp
10) cat - catenates files
● cat 123.txt - dumps the contents of '123.txt' to STDOUT
● cat 123.txt 456.txt dumps both files to STDOUT
● cat 123.txt 456.txt > 123456.txt - creates new catenated file
● cat 123.txt 456.txt >> abc appends a file
● cat key.txt | more : Displays the contents of the file with forward paging
● less key.txt : Scroll forward: Ctrl-f
Scroll backward: Ctrl-b
End of file: G
Quit less: q
11) mv - moves files and renames files
● mv file.txt file1.txt - It renames a file
12) rm - removes files/directories
● rm file.txt
● rm -rf 456.txt - removes recursively and enforces
● rm -r directory : It removes directory
13) stat - reveals statistics of files
● stat 123456.txt - reveals full attributes of the file
14) find - finds files using search patterns
● find /home/cloudage -name 'filename / directory name'
Note: 'find' can search for fields returned by the 'stat' command
● find /home/cloudage -name *cache*
● find /home/cloudage/hadoop -size +1k : It find files larger than 1k in
/home/cloudage/hadoop
● find /home/cloudage/ -name '*.txt' : It will find all files with extension .txt
15) seq - echoes a sequence of numbers
● seq 1000 > 1thousand.txt - creates a file with numbers 1-1000
16) su - switches users
● su - to switch to another user
17) head : It displays opening lines of text files
18) tail - displays the closing lines of text files
19) wc - counts words and optionally lines of text files
● wc -l 123.txt : It prints the no of lines in a file.
20) file - determines file type
● file /home/cloudage key1.txt
21) tty - reveals the current terminal
22) cp - copies files
● cp 123.txt test/ By default, 'cp' does NOT preserve the original
modification time
● cp file.txt file1.txt (for files)
● cp -a copy (for directories)
● cp -v key.txt hadoop It paste the copied file
23) history display the list of the last 1000 commands
● !262 runs the 262 command
24) aspell -c <filename> check the spelling in the file
25) whereis display all paths
a. whereis <directory/filename> displays where the file/directory is located
26) hostname : display hostname name of the user
27) id display id info of current user
● id -u display user id of current user
● id -un display username of current user
● id -g display group id of current user
● id -gn display groupname of current user
28) uptime display for how long the system has been running
29) users display no. of users currently logged in
30) who display users logged in the system with their
respective terminals and time since logged in
31) w : display is details which files are open on which
terminal
32) zip : It is used to compress the file
● zip filename.zip *.txt : It compresses the file
● zip -p password filename.zip *.txt : It password protect the file
zip -e filename.zip *.txt
33) unzip : It is used to unzip the zip file
● unzip filename.zip *.txt : It unzips the file
● unzip --ql key.zip *.txt : It quietly unzips the file
34) gzip : It compresses the file
● gzip -c filename.txt > filename.txt.gz
35) tar : It creates a tar file
● tar -cf filename.tar *.txt
● tar -xf filename.tar *.txt : It is used to extract the compressed file
● tar -czf filename.tar.gz directory name : It create a tar with gzip
compression
36) ps : It displays your currently actively processes
● ps aux | grep 'telnet' : It will find all processes id related to telnet process
37) top : It displays all running processes
38) ip addr show: Displays all network interfaces and ip address
41) netstat -tupl : It lists all active listening ports
39) wget file link : It is used to download file
40) locate filename: It find all instances of file
41) scp filename directory name : It securely copies the file
42) du
● du -ah : It displays disk usage in human readable format
● du -sh : It displays total disk usage in current directory
43) echo $PATH : It displays the $PATH environment variable