Linux Command Line Every Hacker Should Master

Linux Command Line

Basic Commands

 

1. pwd (Print Working Directory):

 Description: This command displays the current directory you are in.

 

$ pwd
pwd /home/user/documents

 

2. ls (List):

 Description: Use `ls` to view files and directories in the current directory.

 

$ ls
ls file1.txt file2.txt folder1 folder2

 

3. cd (Change Directory):

 Description: Navigate through directories using `cd`.

 

$ cd
cd /home/user/documents

 

4. touch:

 Description: Create empty files by using the `touch` command.

 

$ touch
touch new_file.txt


5. cp (Copy):

 Description: Duplicate files using the `cp` command.

 

$ cp
cp file1.txt /home/user/documents/folder2


6. mv (Move):

 Description: Relocate files with the `mv` command. This command is also used for renaming files.

 

$ mv
mv file2.txt /home/user/downloads/file2_new.txt


7. rm (Remove):

 Description: Delete files permanently using the `rm` command. Exercise caution with this command.

 

$ rm
rm unwanted_file.txt



File Operations

Files are at the heart of any system. Here are some useful commands for handling files:


8. nano:

 Description: A simple text editor to create and edit files.

 

$ nano
nano new_file.txt

 

9. cat:

Description: Concatenate and display the content of a file.

 

$ cat
cat file1.txt

 

10. grep:
Description: Search for specific patterns in files using the `grep` command.

 

$ grep
grep “keyword” file1.txt

 

11. head:

Description: Display the beginning of a file.

 

$ head
head file1.txt

This is the first line.
This is the second line.

 

12. tail:

Description: Display the end of a file.

 

$ tail
tail file1.txt

This is the ninth line.
This is the tenth line.

 

 

Directory Management

Managing directories is crucial during ethical hacking. Here’s how:

 

13. mkdir (Make Directory):

 Description: Create a new directory using the `mkdir` command.

 

$ mkdir
mkdir new_directory

 

14. rmdir (Remove Directory):

 Description: Delete an empty directory using the `rmdir` command.

 

$ rmdir
rmdir empty_directory

 

15. rm -r (Remove Recursive):

 Description: Remove a directory with all its contents using the `rm -r` command.

 

$ rm -r
rm -r directory_to_remove

 

 

File Permissions

Understanding and managing file permissions are essential for ethical hacking. Here are some commands to help you with that:

 

16. chmod (Change File Permissions):

 Description: Change file permissions (read, write, execute) for users.

 

$ chmod u
chmod u=rwx file1.txt

 

17. chown (Change File Ownership):

 Description: Change file ownership.

 

$ chmod new
chown new_owner file1.txt

 

Process Management

In ethical hacking, understanding, and controlling processes are essential. Here’s how:

 

18. ps (Process Status):

 Description: View information about active processes.

 

$ ps
PID TTY TIME CMD
345 pts/0 00:00:00 bash
912 pts/0 00:00:00 ps


19. top:

 Description: Monitor real-time system processes.

 

20. kill:

 Description: Terminate a process by identifying its PID (Process ID).

 

$kill
kill 345

 

Networking

Discovering network information is vital in penetration testing. Let’s explore some relevant commands:

 

21. ifconfig:

 Description: Obtain network interface configuration details.

 

$ifconfig

eth0

flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.100 netmask 255.255.255.0 broadcast 192.168.0.255

 

22. ping:

 Description: Check connectivity to a target host by pinging it.

 

$ping
ping www.example.com 

 

23. nmap:

 Description: Perform network exploration and security auditing.

 

$nmap
nmap -F 192.168.0.1 

 

24. netstat:

 Description: Show network statistics.

 

$netstat
netstat -tuln 

 

Archiving and Compression

Archiving and compression are useful for managing files efficiently. Here are some commands to help with that:

 

25. tar:

Description: Create or extract tar archives.

 

$tar
tar -cvf archive.tar file1.txt file2.txt 


26. gzip:

 Description: Compress files.

 

$gzip
gzip file1.txt 


27. gunzip:

 Description: Decompress gzip files.

 

$gunzip
gunzip file1.txt.gz 

 

28. zip and unzip:

 Description: Create or extract zip archives.

 

$zip and unzip

zip archive.zip file1.txt file2.txt
unzip archive.zip 

 

System Information

Knowing the system’s details is crucial for understanding its capabilities. Here are some commands for that:

 

29. uname:

 Description: Display system information.

 

$uname

uname -a
Linux myhostname 4.15.0-65-generic #74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux 

 

30. df:

 Description: Show disk space usage.

 

$df
df -h

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 30G 70G 30% /

 

31. free:

 Description: Display memory usage.

 

$free

free -h
total used free shared buff/cache available
Mem: 7.8G 2.3G 3.1G 207M 2.3G 5.2G
Swap: 2.0G 0B 2.0G


32. who:

 Description: Show users currently logged in.

 

$who

who
user pts/0 Jul 26 15:30 (192.168.0.101)

 

Advanced Commands for Ethical Hacking

As an ethical hacker, you need powerful tools for network analysis and security assessment. Here are some advanced commands:

 

33. netcat:

 Description: Network utility for reading from and writing to network connections.

 

$nc
nc -l -p 8080

 

34. wireshark:

 Description: Analyze network traffic in real-time.

 

35. tcpdump:

 Description: Capture network packets.

 

$ tcpdump
tcpdump -i eth0

 

36. ssh:

 Description: Securely connect to remote systems.

 

$ ssh
ssh user@remote_host

 

37. scp:

 Description: Securely copy files between local and remote systems.

 

$ scp

scp file1.txt user@remote_host:/home/user/documents

 

38. openssl:

 Description: Perform cryptographic operations.

 

$ openssl

openssl

enc -aes256 -salt -in file.txt -out encrypted_file.enc

 

File Analysis

Files often conceal valuable information. Here are commands to help you analyze files:

 

39. file:

 Description: Determine file type.

 

$ file

file file1.txt
file1.txt: ASCII tex

 

40. strings:

 Description: Extract human-readable strings from binary files.

 

$ strings
strings binary_file

 

 

User and Group Management

Managing users and groups is crucial for controlling access and privileges. Here are some commands to help with that:

 

41. useradd:

 Description: Add a new user.

 

$ useradd
useradd new_user

 

42. passwd:

 Description: Change user password.

 

$ passwd
passwd new_user

 

43. groupadd:

 Description: Add a new group.

 

$ groupadd
groupadd new_group

 

44. usermod:

 Description: Modify user settings.

 

$ user mod
usermod -aG new_group new_user

 

45. groupmod:

 Description: Modify group settings.

 

$ groupmod
groupmod -n new_group_name old_group_name

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top