Jump to content

Recommended Posts

Posted (edited)

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.