Jump to content
Sign in to follow this  
PiNoY

25 Quick Linux Command Line Tips - Part 3

Recommended Posts

Following up recent quick linux CLI tip Part 2 here.

 

51. How to know which ports are listening from your IP address?

 

# nmap -sT -O your-ip-address

 

52. How to grep an exact match?

 

# grep -w textfile.txt

 

53. How to reverse grep matches?

 

# grep -v textfile.txt

 

54. How to know which linux service name is assigned to what port?

 

Assuming for port 443

 

# cat /etc/service | grep -w 443

 

55. How to get the first 10 lines of a file?

 

# head -10 testfile.txt

 

56. How to get the last 10 lines of a file?

 

# tail -10 testfile.txt

 

57. How to get the first column of a file?

 

# awk '{print $1}' testfile.txt

 

58. How to get the first and second columd of a file?

 

# awk '{print $1 " " $2}' testfile.txt

 

59. How to get the first column of a file having consistent field separator pattern?

 

Field separator character patterns is /

 

# awk -F/ '{print $1}' testfile.txt

 

60. How to get the second column of a file having consistent field separator pattern?

 

# awk -F/ '{print $2}' testfile.txt

 

61. How to show contents of a text file?

 

# cat testfile.txt

 

62. How to show contents of text file pausing ever page or one screenful at a time?

 

# more testfile.txt

# less testfile.txt

 

63. What is the big difference between more and less?

 

less linux command has much more extensive enhancements compared with more.

You can also scroll up interactively via control keystrokes using less while the other one does not allow you to do that.

less does not need to read the entire file to buffer when showing a screenful content of a file and furthermorel less is faster than more on accessing big filesize.

 

64. How do you delete all numbers and digits from contents of a file?

 

# tr -d [:digit:] < testfile.txt

 

65. How do you sort contents of a text file in descending order?

 

# sort -r newfile.txt

 

66. How do you create a file using touch (without opening it interactively for writing)?

 

# touch newfile.txt

 

67. How do you change the date of all files in one folder?

 

# touch *

 

68. How do you create a file using tee?

 

# tee newfile.txt

 

and start typing, press Control+D when done

 

69. How do you query currently installed package offline from your system?

 

# rpm -qa sendmail

 

70. How do you query packages for something-like package ?

 

# rpm -qa | grep sendmail

# rpm -qa *sendmail*

 

71. What files comes with a particular rpm package?

 

# rpm -ql `rpm -qa postfix*`

 

72. How to get more info of rpm package?

 

# rpm -qi packagename

# rpm -qi postfix-2.4.3-2.fc7

 

73. Where does rpm stores its rpm database?

 

# cd /var/lib/rpm

# ls -la __*

 

74. How to mount CD drive after inserting the disk?

 

# mount /dev/cdrom /mnt/CD

 

75. How to know if fedora detects your Nokia N70 via USB?

 

# lsusb

Edited by Fearless News

Share this post


Link to post
Share on other sites
Sign in to follow this  

×