Linux Commands-2
Linux Commands-2
2.ls -al – Lists all files, including hidden ones, with detailed information.
16. echo "Hello" > file.txt – Writes text to a file (overwrites existing content).
23. find / -name "file.txt"- Searches for a file by name starting from the root directory.
24. find . -type f -name "*.log” - Finds all logs in the current directory.
25. Locate file.txt - Finds the location of a file using a pre-built index.
30. awk '{print $1}' file.txt – Prints the first column of a file.
31. awk -F: '{print $1}' /etc/passwd – Prints the first field of the
/etc/passwd file, separated by colons.
32. sed 's/old/new/g' with "new" in a file.file.txt – Replaces all occurrences of "old" with “new”
in a file.
60. nohup command & – Runs a command in the background, ignoring hangups.
112. dirname /path/to/file.txt – Extracts the directory path from a given file path.
117. cut -d':' -f1 /etc/passwd – Extracts the first field from a
colon-separated file.
119. tee output.file.txt – Writes output to both a file and the standard
133. uptime -p – Shows how long the system has been running.
138. dmesg | grep error – Searches the kernel logs for errors.
191. strace -e open ls – Shows file open system calls used by ls.
192. tcpdump -XX – Captures packets with hex and ASCII output.
197. uptime -p – Shows how long the system has been running in a human-friendly format.
201. vmstat 1 5 – Displays system performance statistics every second for 5 iterations.
202. sar -u 5 3 – Reports CPU usage every 5 seconds for 3 iterations.
207. mpstat -P ALL 5 – Displays CPU usage for all cores every 5 seconds.
211. ulimit -n 10240 – Changes the maximum number of open file descriptors.
212. getfacl file.txt – Displays ACL (Access Control List) permissions of a file.
248. tcpdump -nn -s0 -X -i eth0 port 80 – Captures and displays raw HTTP traffic.
251. rsync -avz /src/ user@remote:/dest/ – Syncs files\ securely over SSH.
252. rsync -a --delete /src/ /dest/ – Synchronizes directories and removes extra files.
253. scp -P 2222 file.txt user@remote:/path/ – Transfers a file using a non-default SSH port.
254. ssh user@remote -p 2222 – Connects to a server using a different SSH port.
259. chmod 600 ~/.ssh/id_rsa – Sets secure permissions on an SSH private key.
263. useradd -m -s /bin/bash newuser – Creates a new user with a home directory.
264. usermod -aG sudo username – Adds a user to the sudo group.
272. echo "0 2 * * * /path/to/script.sh" | crontab - –Schedules a cron job to run a script at 2 AM
daily.
279. date "+%Y-%m-%d %H:%M:%S".– Displays date and time in a specific format.
280. find /var/log -type f -mtime +30 -delete – Deletes log files older than 30 days.
282. du -ah /var/log | sort -rh | head -10 – Lists the 10 largest log files.
289. tune2fs -c 100 /dev/sda1 – Forces a filesystem check every 100 mounts.