TimCS.Co.Uk Linux Linux Useful Information Useful Linux commands
Useful Linux commands

Question(s) Answer(s)
How can I find the most recently file created and copy it in Linux or Unix ls -1t <filename/wildcard > | cp `head -n1` <destination>
How can I show the top 10 largest areas from where I currently am. du -x -k | sort -nr | head -10
How do I list just directories from where I am in either Unix or Linux? ls -ail | grep drw
How do I get a list of groups that a user belongs to groups <username>
How do I get a list of users connected to samba? samba -b or samba -d
Is there away of renaming a directory? mv <directory name> <new directory name>
Using vi, how can I search for date which includes the / as its format? When in vi , to do a standard search the / is pressed to switch to search mode. To search for a date e.g. 01/01/2006 entered 01[/]01[/]2006
How can I get a count of files in the directory that I am in using Linux or Unix? ls | wc -l
How can I find out when the system was last rebooted shutdown in Unix/Linux who -b
How can I scroll through previously entered commands when the up and down arrow keys do not work? Try using Ctrl + P for previous commands and Ctrl + N for next commands
How do I search for a running process by its name? ps -ef | grep process name
How can I insert text in front of every line in VI while in vi move to the command line by typing : then straight afterwards type %s/^/text to insert/g and press return
How can I delete a file that has the character - (dash/hyphen) at the beginning? the rm command thinks this to be a parameter. To delete this file type rm -- <filename> the first two dashes makes rm ignore the - that is at the start of the files name. The same method applies if you wish to do a ls and in the list of files one starts with a - (dash/hyphen). E.G. type ls -- <wildcard/file list spec>
How do I find and replace text in VI Whilst in the file in VI, go to the command line by typing the colon : then straight after that type %s/text to replace/replacement text/g and press enter.

Please note :

If the text to be replaced and the text that will be replacing it have backslashes (\), then a further backslash needs to be entered in order for the routine to find and replace it.

e.g. f:\fred.txt wants to be replaced with e:\fred.txt then it needs to be entered as :%s/f:\\fred.txt/e:\\fred.txt/g
How can I list printers from a command shell in either Unix or Linux Type lpstat -t
How can I remove a print job for a specific printer from the command shell? Type cancel <printer name as shown in lpstat -t>-<job id as shown in lpstat -t>.

E.g. if the printer device is called office1 and the jobid is named 1234 then this command would clear the job:
cancel office1-1234

This command can work with Linux and Unix.

Another command that can be used in Linux is lprm. Using the same printer name and jobid as above this is how lprm would remove the print job:
lprm -Poffice1 1234
What command shows the system disk space If using Linux, do this type df -h . Otherwise in Unix type dfspace
How can I copy all files in a directory from one file extension to another. For instance, all files *.tif to *.bmp? One way of doing this using the example given is as follows :
rename .tif .bmp * . This will rename all files ending in tif to bmp
How do I find the chipset of a network card? type lspci -v or lspci | grep Ethernet at a command prompt, then look for the line that has "Network controller" if you have typed the first command as the second command shows all networks card only.
 

Powered by Joomla!. Valid XHTML and CSS. Credits go to Gareth Flowers for his help with this site.