1. Sudo !! Command Running the Command Without Specifying Sudo Command Will Give You Permission Denied Error

1. Sudo !! Command Running the Command Without Specifying Sudo Command Will Give You Permission Denied Error

Linux command line attracts most of the Linux Enthusiastic. A normal Linux user generally posses a vocabulary of roughly 50-60 commands to carry out their day-to- day task. Linux commands and their switches remains the most valuable treasure for a Linux-user, Shell-script programmer and Administrator. There are some Linux Commands which are lesser Known, yet very useful and handy irrespective of the fact whether you are a Novice or an Advanced User. Lesser Known Linux Commands This very article aims at throwing light on some of the lesser known Linux commands which surely will help you to handle your Desktop/Server more efficiently. 1. sudo !! command Running the command without specifying sudo command will give you permission denied error. So, you don’t need to rewrite the whole command again just put ‘!!‘ will grab the last command. $ apt-get update E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied) E: Unable to lock directory /var/lib/apt/lists/ E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? $ sudo !! sudo apt-get update [sudo] password for server: … .. Fetched 474 kB in 16s (28.0 kB/s) Reading package lists... Done server@localhost:~$ 2. python command The below command generates a simple web page over HTTP for the directory structure tree and can be accessed at port 8000 in browser till interrupt signal is sent. # python -m SimpleHTTPServer Directory Structure Tree 3. mtr Command Most of us are familiar with ping and traceroute. How about combining the functionality of both the command into one with mtr command. In case mtr is not installed into your machine, apt or yum the required package. $ sudo apt-get install mtr (On Debian based Systems) # yum install mtr (On Red Hat based Systems) Now run mtr command to start investigating the network connection between the host mtr runs on and google.com. # mtr google.com mtr command 4. Ctrl+x+e Command This command is very much useful for administrator and developers. To Automate day-to- day task an administrator needs to open editor by typing vi, vim, nano, etc. How about firing instant editor (from terminal). Just Press “Ctrl-x-e” from the terminal prompt and start working in editor. Download Linux Command Line Cheat Sheet 5. nl Command The “nl command” number the lines of a file. Number the lines of a file say ‘one.txt‘ with lines say (Fedora, Debian, Arch, Slack and Suse). First list the content of a file “one.txt” using cat command. # cat one.txt fedora debian arch slack suse Now run “nl command” to list them in a numbered fashion. # nl one.txt 1 fedora 2 debian 3 arch 4 slack 5 suse 6. shuf Command The “shuf” command randomly select lines/files/folder from a file/folder. First list the contents of a folder using ls command. # ls Desktop Documents Downloads Music Pictures Public Templates Videos # ls | shuf (shuffle Input) Music Documents Templates Pictures Public Desktop Downloads Videos # ls | shuf -n1 (pick on random selection) Public # ls | shuf -n1 Videos # ls | shuf -n1 Templates # ls | shuf -n1 Downloads Note: You can always replace ‘n1‘ with ‘n2‘ to pick two random selection or any other number of random selection using n3, n4.… 7. ss Command The “ss” stands for socket statistics. The command investigates the socket and shows information similar to netstat command. It can display more TCP and state informations than other tools. # ss State Recv-Q Send-Q Local Address:Port Peer Address:Port ESTAB 0 0 192.168.1.198:41250 *.*.*.*:http CLOSE-WAIT 1 0 127.0.0.1:8000 127.0.0.1:41393 ESTAB 0 0 192.168.1.198:36239 *.*.*.*:http ESTAB 310 0 127.0.0.1:8000 127.0.0.1:41384 ESTAB 0 0 192.168.1.198:41002 *.*.*.*:http ESTAB 0 0 127.0.0.1:41384 127.0.0.1:8000 8. last Command The “last” command show the history of last logged in users. This command searches through the file “/var/log/wtmp” and shows a list of logged-in and logged-out users along withtty’s. # last server pts/0 :0 Tue Oct 22 12:03 still logged in server tty8 :0 Tue Oct 22 12:02 still logged in … ... (unknown tty8 :0 Tue Oct 22 12:02 - 12:02 (00:00) server pts/0 :0 Tue Oct 22 10:33 - 12:02 (01:29) server tty7 :0 Tue Oct 22 10:05 - 12:02 (01:56) (unknown tty7 :0 Tue Oct 22 10:04 - 10:05 (00:00) reboot system boot 3.2.0-4-686-pae Tue Oct 22 10:04 - 12:44 (02:39) wtmp begins Fri Oct 4 14:43:17 2007 9. curl ifconfig.me So how do you obtain your External IP address? Using google?. Well the command output your external IP address right into your terminal. # curl ifconfig.me Note: You might don’t have curl package installed, you have to apt/yum to install package. 10. tree command Get the current directory structure in tree like format. # tree . |-- Desktop |-- Documents | `-- 37.odt |-- Downloads | |-- attachments.zip | |-- ttf-indic-fonts_0.5.11_all.deb | |-- ttf-indic-fonts_1.1_all.deb | `-- wheezy-nv-install.sh |-- Music |-- Pictures | |-- Screenshot from 2013-10-22 12:03:49.png | `-- Screenshot from 2013-10-22 12:12:38.png |-- Public |-- Templates `-- Videos 10 directories, 23 files 11. pstree This commands shows all the processes running currently along with associated child process, in a tree like format similar to ‘tree‘ command output. # pstree init─┬─NetworkManager───{NetworkManager} ├─accounts-daemon───{accounts-daemon} ├─acpi_fakekeyd ├─acpid ├─apache2───10*[apache2] ├─at-spi-bus-laun───2*[{at-spi-bus-laun}] ├─atd ├─avahi-daemon───avahi-daemon ├─bluetoothd ├─colord───{colord} ├─colord-sane───2*[{colord-sane}] ├─console-kit-dae───64*[{console-kit-dae}] ├─cron ├─cupsd ├─2*[dbus-daemon] ├─dbus-launch ├─dconf-service───2*[{dconf-service}] ├─dovecot─┬─anvil │ ├─config │ └─log ├─exim4 ├─gconfd-2 ├─gdm3─┬─gdm-simple-slav─┬─Xorg │ │ ├─gdm-session-wor─┬─x- session-manag─┬─evolution-a+ │ │ │ │ ├─gdu-notific+ │ │ │ │ ├─gnome-scree+ │ │ │ │ ├─gnome-setti+ │ │ │ │ ├─gnome-shell+++ │ │ │ │ ├─nm-applet──+++ │ │ │ │ ├─ssh-agent │ │ │ │ ├─tracker-min+ │ │ │ │ ├─tracker-sto+ │ │ │ │ └─3*[{x-sessi+ │ │ │ └─2*[{gdm-session-wor}] │ │ └─{gdm-simple-slav} │ └─{gdm3} ├─6*[getty] ├─gnome-keyring-d───9*[{gnome-keyring-d}] ├─gnome-shell-cal───2*[{gnome-shell-cal}] ├─goa-daemon───{goa-daemon} ├─gsd-printer───{gsd-printer} ├─gvfs-afc-volume───{gvfs-afc-volume} That’s all for now. In the next article of mine I would cover certain other lesser known Linux commands which would be fun. Till then stay tuned and connected to Tecmint. Like and share us and help us get spread. 12. <space> Command Every piece of command you type in terminal gets recorded in the history and can be retried using history command. How about cheating history command? Yeah you can do it and its very easy. Just put one or more white space before typing a command in terminal and your command wont be recorded. Lets give it a try, we will try five common Linux commands (say ls, pwd, uname, echo “hi”and who) in terminal after one white space and check if these commands are docked in history or not. avi@localhost:~$ ls avi@localhost:~$ pwd avi@localhost:~$ uname avi@localhost:~$ echo “hi” avi@localhost:~$ who Now run ‘history‘ command to see whether these above executed commands are recorded or not. avi@localhost:~$ history 40 cd /dev/ 41 ls 42 dd if=/dev/cdrom1 of=/home/avi/Desktop/squeeze.iso 43 ping www.google.com 44 su You see our last executed commands are not logged. we can also cheat history by using an alternate command ‘cat | bash‘ of-course without quotes, in the same way as above. 13. stat Command The stat command in Linux displays the status information of a file or filesystem. The statshows a whole lot of information about the file which name is passed as argument. Status Information includes file Size, Blocks, Access Permission, Date-time of file last access,Modify, change, etc. avi@localhost:~$ stat 34.odt File: `34.odt' Size: 28822 Blocks: 64 IO Block: 4096 regular file Device: 801h/2049d Inode: 5030293 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 1000/ avi) Gid: ( 1000/ avi) Access: 2013-10-14 00:17:40.000000000 +0530 Modify: 2013-10-01 15:20:17.000000000 +0530 Change: 2013-10-01 15:20:17.000000000 +0530 14. <alt>. and <esc>. The above key combination is not actually a command but a tweak which put the last command argument at prompt, in the order of last entered command to previous entered command. Just press and hold ‘Alt‘ or ‘Esc‘ and continue pressing ‘.‘. Download Linux Command Line Cheat Sheet 15. pv command You might have seen simulating text in Movies specially Hollywood Movies, where the text appears as if it is being typed in the Real time. You can echo any kind of text and output in simulating fashion using ‘pv‘ command, as pipelined above. The pv command might not be installed in your system, and you have to apt or yum the required packages to install ‘pv‘ into your box. root@localhost:# echo "Tecmint [dot] com is the world's best website for qualitative Linux article" | pv -qL 20 Sample Outpit Tecmint [dot] com is the world's best website for qualitative Linux article 16. mount | column -t The above command shows the list of all the mounted filesystem in a nice formatting with specification. avi@localhost:~$ mount | column -t Sample Outpit /dev/sda1 on / type ext3 (rw,errors=remount-ro) tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) udev on /dev type tmpfs (rw,mode=0755) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620) fusectl on /sys/fs/fuse/connections type fusectl (rw) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) nfsd on /proc/fs/nfsd type nfsd (rw) 17.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    79 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us