Linux, as a powerful and versatile operating system, offers a wide range of commands that can greatly enhance your productivity and efficiency. Whether you are a beginner or an experienced user, mastering some essential Linux commands is invaluable.
In this article, we will explore several useful Linux commands along with examples of their usage.
| 1 | To print today’s date: | date |
| 2 | To print hostname of the pc: | hostname |
| 3 | To perform basic mathematical calculation: | expr [number 1 (+/-/(/)/*) number 2 (+/-/(/)/*) number 3 . . . ] |
| 4 | To print string of characters: | echo “Any string” |
| 5 | To print name of the OS: | uname |
| 6 | To print details of the OS: | uname -a |
| 7 | To print version of the bash: | bash –version |
| 8 | Debugging a program: | echo $? |
| 9 | To print history of commands typed on the terminal: | history |
| 10 | To change hostname: | hostnamectl set-hostname –static “name of your choice” |
| 11 | To see only files: | ls |
| 12 | To see lists even hidden files: | ls -a |
| 13 | To see details of the files: | ls -l |
| 14 | To see details of the normal and hidden files: | ls -la |
| 15 | To remove a file from current directory: | r m [filename in any format] |
| 16 | To remove all files from current directory: | rm -a |
| 17 | To change directory, to move around to different folders: | cd ./name of the directory |
| 18 | To return directly to home directory: | cd |
| 19 | To return to previous folder: | cd .. |
| 20 | To make a directory: | mkdir |
| 21 | To remove a directory: | rmdir |
| 22 | To remove a directory and all of its contents recursively: | rmdir -r [name of the directory] |
| 23 | To change permissions of accessibility of file in the terminal: | chmod +x ‘filename’ |
| 24 | To download a folder: | (wget or (curl -L)) http://example.com/download.zip -o download.zip |
| 25 | To show current directory: | pwd |
| 26 | To read a file from terminal: | cat <name of the file in .txt format> |
| 27 | To read a file one at a time from terminal: | less [name of the file in .txt format] |
| 28 | To copy a file: | cp <name of the file to be copied> <new name of the file that will be copied> |
| 29 | To move a file: | mv <name of the file> <directory file to be moved> |
| 30 | To create a file: | touch <filename.extension> |
| 31 | To open a folder: | nautilus /<destination of the directory> |
| 32 | To create shortcut for commands: | alias <user defined shortcut key>=‘<command>’ |
| 33 | To see list of block devices i.e. internal and external hard drives: | lsblk |
| 34 | To burn .iso image in USB: | sudo dd if=nameoffile.iso of=/dev/destinationdisk bs=1M |
| 35 | To have access as root user: | sudo passwd root followed by su – |
| 36 | To open terminal text editor either vim or nano: | vim (for vim) or nano (for nano) |
| 37 | To check architecture if 32 or 64 bit: | arch result x86_64 for 64 bit and i386 for 32 bit |
| 38 | To display HTTP header(information about server and cookies): | printf ‘HEAD / HTTP/1.1\r\nHost: [host address]\r\n\r\n’ | nc [host address] 80 |
| 39 | To check IP address and details about mail handled of a website: | host [domain name] |
| 40 | To test network connection if it is established and speed of the connection: | ping [domain name] |
| 41 | To check how network is configured. Displays NAT ip addresses of ethernet connection and wifi and all other information: | ifconfig |
| 42 | To check all the information of network devices whether they are active or inactive: | ifconfig -a |
| 43 | To enable or disable one of the networking device: | ifconfig [name of the device] [up to enable and down to disable] |
| 44 | To display ethernet address of the current network card: | arp |
| 45 | To change ip address: | ifconfig (name of the device) ip address of your desire |
| 46 | To change subnet mask: | ifconfig (name of the device) netmask 255.255.255.1 |
| 47 | To change mac address: | ifconfig (name of the device) hw ether 43:42:12. . |
| 48 | To display more information about wifi: | iwconfig |
| 49 | To show only ip addresses of all the devices rather than just domains connected to machine: | netstat -nr |
| 50 | To display the usage of the network cards(to show how many packets in bytes are sent and transferred): | netstat -i |
| 51 | To look for active internet connections: | netstat -ta |
| 52 | To look for active internet connections: | netstat -tan |
| 53 | To find detailed information of a domain: | whois (domain name) |
| 54 | To perform detailed DNS lookup: | dig (domain name) |
| 55 | To perform DNS lookup: | nfslookup (domain name) |
| 56 | To trace no. of hops taken to access domain and lists all the routers the packets come across: | traceroute (domain name) |
| 57 | To show hostname: | hostname |
| 58 | To show ip addresses both ipv4 and and ipv6: | hostname -I |
| 59 | To capture all packets that are going to and from the pc: | sudo tcpdump |
| 60 | To capture only certain amount of packets: | sudo tcpdump -c no. of packets to be captured(amount in numbers) |
| 61 | To capture only certain amount of packets in hexadecimal or ascii format: | sudo tcpdump (-XX for hexa or -A) for ASCII -c 5 |
| 62 | To compile a file in .c format: | clang file.c |
| 63 | Executable file a.out is generated. To run this file: | ./a.out |
| 64 | To generate executable file with nicer name: | clang -o file file.c . Now, ./file can be run. |
| 65 | To generate assembly code: | clang -S filename.c |
| 66 | To disable assertions: | – o filename.py |
| 67 | To compile a java file to generate .class executable file: | javac filename.java |
| 68 | To run java file on terminal or console: | java filename |


Pingback: Top 40 Useful Linux Command Snippets - Tech Hyme