techiehub.in

Linux Handy Commands

Check Linux distribution:

cat /etc/os-release

Tail all logs in a directory with subfolders:

find . -name "*.log" | xargs tail -f

Create a user/password:

sudo adduser <user-name>

Add user to sudoers list:

sudo usermod -a -G wheel <user-name>

Check if the user exist/created:

cat /etc/passwd | grep <user-name>

List all sudoers:

cat /etc/sudoers

Switch users:

su - <user-name>

Change password for a user:

su -
passwd <user-name>

Find directory:

find ./ -type d -name <directory-name>

Find file in current directory

find ./ -name <file-name>

Find the count of search results

ls -l | grep <text-to-be-searched> | wc -l

Print disk usage of a given folder:

Navigate to the folder: cd <path-to-folder>
du -sh -- *

Pretty print the partition disk space

df -h

Pretty print the disk space of current directory

df -h .

Find Geo Location of a linux VM:

curl ipinfo.io

File transfer between linux machines:

scp <path-of-files-to-be-transferred> <dest-machine-user>@<dest-machine-ip>:<dest-path>

Cut fist n lines from a file and store in a different file:

head -n <numnber-of-lines-to-be-cut> <file-path>
E.g. head -n 50 myfile.txt > save-result.txt

Create Alias:

alias <alias-name>="<alias-command>"
E.g. alias nav-to-my-directory ="cd my-directory-path"

Categories