Basic Linux Commands(with images)
Basic Linux Commands(with images)
1) ssh - First open the ubuntu terminal / For windows use putty and then open terminal
cd Downloads/ - where the key is kept that directory.
Use nano for creating file / opening file.
Example- nano singlenode.pem and hit enter
Now copy the pem file data and paste it in nano singlenode.pem file for windows, for linux
just exit(Ctrl X).
Now in AWS instance click on Connect and copy chmod 400 singlenode.pem Hit enter
Now copy this
ssh -i "singlenode.pem" [email protected]
ssh is a protocol
-i is an identifier
singlenode.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
5) cd
find / -mtime 50
find / -atime 50
28) uptime : It display for how long the system has been running
29) users : It display no. of users currently logged in
● 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
Top -u afshin
cat top-output.txt
PERMISSION EXAMPLE
U G W
Ls -l filename
LEGEND
U = User
G = Group
W = World
r = Read
w = write
x = execute
- = no access
45) du
We can make this more useful by specifying how deep we should check with
--max-depth, which can be shortened to the -d option. By setting this to 1, we will
look 1 directory deep and display the size in use of all directories within the
current location.
Du -d 1
du -h -d 1 /
Now we can see the space used within the directories as well as the
specific files within.
du -h -d 2 -a
With the -c option we can have the total space reported at the bottom of the
output
du -h -d 2 -c
e) Sort Output By Disk Usage Size
While not built into the du command, we can pipe it to the sort command in
order to list files in order of file size, such as smallest to largest. This is
extremely useful as we can search the whole disk and order the output
based on file size, allowing us to quickly locate large files.
du -h -a / | sort -h | tail -n 15
While searching for files using disk space to potentially be removed it can
be beneficial to view the last modified time stamp. For example if used disk
space is increasing over time then the most recently modified files are a
good place to investigate, for instance we may have a large log file that is
constantly being modified and written to.
du -h -d 1 --time -a
This may be helpful if we want to search for files larger than a specified
size which would be useful in finding large single files that may be using
the majority of your disk space.
du -h -t 100M -a /
With the --exclude option we can optionally not show anything that
matches a specified pattern in the search results
du -h -d 1 -a --exclude="*.txt"
i) Piping du
This will search your entire filesystem sort the results by size and then show
only the top ten results. It’s essentially a shortcut for the top ten largest files on
your machine
du -a / | sort -n -r | head -n 10
46) df
a) Running df
If we run the df command with no options, it will print out disk usage information
for all mounted file systems
Df
b) Print Totals
So far with df we can print out the usage of each individual file system. With the
--total option we can get an overall result
df --total -h