|
|
|
|
|
|
|
Useful Ubuntu Linux Commands
|
|
Linux commands can be far from intuitive, with files related to a single application seemingly scattered throughout various locations, such as usr, bin, etc, var. This can make it difficult to recall how to invoke certain essential but not every-day commands. This page lists these commands in a single place. |
compton, 6 September 07
Updated 2 June 10
|
Read a file and perform a command for each lineThe following trivial example simply copies a file from inputfile to outputfile, but naturally you can replace the echo command with any other of your choosing.
cat inputfile | while read line;do echo $line >> outputfile; done
Useful Additions to .bash_profile# set xterm title and shell prompt export PS1="\[\e]2;\u@\H \w\a\e[31;1m\]\u@\H \w\[\e[0m\] "
# ignore duplicate HISTCONTROL=erasedups:ignorespace
# ignore these commands in history file HISTIGNORE=l[sla]:cd:pwd:exit:clear
Set Disk Checking to Once per MonthUbuntu defaults to running a disk check every 30 boots, or once a month (I think). The following command will set it to just check once per month, regardless of how many times you reboot:
sudo tune2fs -c 0 -i 1m /dev/sda1
Search within Selected Files Recursing Through Foldersgrep has the -r option to do a recursive search through folders under the specified path. However it won't work in conjunction with wildcards such as *.java. To do searches such as this, you need to use it in combination with find and xargs like so:
find ~/startfolder -type f -name '*.java' -print0 | xargs -0 grep 'searchpattern'
Create a tar.gz Compressed Archivetar -cvzpf archive.tar.gz sourcedir1 sourcedir2 The -c option means create a new archive, -v is for verbose, -z indicates it should be a gzipped archive, -p means preserve permissions on files, and -f means use the specified archive file.
List contents of a tar.gz Compressed Archivetar -tzf archive.tar.gz
List All directories containing certain filesfind . -type f -name '*.py' |sed 's#\(.*\)/.*#\1#' |sort -u This will list all directories under the current directory which contain python files.
Flush bash historyThe bash shell keeps a record of commands that have been used in the file ~/.bash_history. However the commands used in the current session are not written to this file until you log out of the current session. If you wish to flush the history to this file before logging out, use the following: history -a 'a' here stands for append - so this is the regular behaviour. If you want, you can use 'w' instead, which will replace the current bash history file with the session history.
List the most recently modified filels -lt | grep ^[^dt] | head -1
Switch to a Virtual Terminal from the command linesudo chvt 1
Display a Unix timestamp in a readable formdate -d @1193144433
Reset WINE (equivalent to a reboot in Windows)wineboot
Restart the pulseaudio deamonpulseaudio -k; pulseaudio -D
Restart Apache2 on Ubuntusudo /etc/init.d/apache2 restart
View Apache2 error loggedit /var/log/apache2/error.log
This location is also where apache keeps its access.log file.
Force Disk Check on Next Rebootsudo touch /forcefsck
Reload Apache2 Config Settingssudo /etc/init.d/apache2 force-reload
Install Apache2 Module (eg ModRewrite)sudo a2enmod module_name
eg sudo a2enmod rewrite
Then force Apache to reload config settings as above.
Regenerate the fonts cache:sudo fc-cache -fv
The default location of system fonts is /usr/share/fonts/. Different font types are grouped into subfolders off here.
Create a symbolic linkln -s /path/to/target /path/to/linkname You can omit the final linkname argument if you want to create a link in the current directory with the same name as the target directory.
Change the target of an existing symbolic linkln -sf /path/to/target /path/to/linkname The 'f' option (or --force) actually overwrites any existing file with the same name & location as the newly created link. |
|
1 2 |
|
|
|
|
|
|