As Linux and the various flavours of Unix are slowly spreading into the world of personal computers, I thought we could collect a few Tips and Tricks here to help each other making the best out of our distributions!
Ideally any Tips posted here should be available for several distributions, but we won't reject any that aren't. :-)
Please state, which distribution(s) the tips were tested with.
I'll start with posting some of my favourites.
*EDIT: For more extensive Tips, check the Linux and Unix articles section 20 12281 Colours in the console bash is one of the most popular shells in the Linux and Unix world and many distributions use it as their standard.
Often however, it's just black and white. But, with a little trick we can make it nice and colourful.
We'll have to edit the file ~/.bashrc - you can use your favourite editor for that (I normally use vim, but nano, gedit or emacs or example will do the job just as well). I'll show how to do the job with vim. Type
in a console window. Normally such a file will already exist, so you'll see some text straight away.
First of all, check if you have these (or similar) lines somewhere, by scrolling down with the arrow keys: -
case "$TERM" in
-
xterm-color)
-
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
-
;;
-
*)
-
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
-
;;
-
esac
-
If so, we'll have to comment it out. To do so, first of all press the key i on your keyboard to start editing mode. Then go to the beginning of each of those lines and enter a # symbol.
Next, we'll add a line underneath. So, go underneath the lines you just edited, press Enter to start a new line and enter the following text: -
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
-
Now press the Esc key and type
to save and exit. To test the settings you just made, type
now - and voilą, the shell shows colours!
This tip was tested under Ubuntu, Debian and Fedora.
Creating aliases for bash
If you work in bash a lot (or in any other shell for that matter, but we'll concentrate on bash), there might be commands you call again and again and again. Especially if these are relatively long, it can be a good idea to create shortcuts for them. A great option here is using aliases. Let me give you two examples: - You want to list more details with ls and preferably do so in colour. The normal command would be
But we'll define an alias for that called ll, which makes life much easier.
- You connect to a certain server via ssh frequently and don't want to call
every time. No problem - we'll define an alias (say tux) to do that.
OK, so how do we do this? First of all, let's create a file ~/.bash_aliases with the command
Now press the i key and type the following lines: -
## some ls aliases
-
alias ls='ls --color=auto'
-
alias la='ls -A'
-
alias lh='ls -l -h'
-
alias ll='ls -l'
-
alias l='ls -CF'
-
-
## some other aliases
-
alias tux='ssh -X 123.456.78.9'
-
OK, so we've defined those now. Finish editing by pressing the Esc key and save and quit by writing
and hitting the Enter button.
Now we'll just have to let bash know about those aliases. Like before, we'll edit a file for that:
Go to the bottom of that file, press i to start editing and in new lines write: -
if [ -f ~/.bash_aliases ]; then
-
. ~/.bash_aliases
-
fi
-
Now, press Esc, type :wq, hit Enter and run
Your new aliases should work now - just type - ll #that's two small 'L's
for example!
This Tip was tested under Ubuntu, Debian and Fedora
subscribing .................................................. .................:)
Having a personal welcome in bash
When you start a new terminal window, you will get a little welcome message like
Linux tux 2.6.24-my-superkernel #1 SMP Sun Oct 31 24:00:01 UTC 2008 i686
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/
This can become pretty boring, so we'll change it. How? Now that's easy!
You'll need to work with root privileges, so either use sudo if installed or change to your root account with su.
Now, you'll want to edit the file /etc/motd - I'll be using vim again:
Keep the d key pressed to delete everything first (the command dd means "delete this line"), then press the i key to start editing. Enter the text you want it so say every time now. When finished, quit editing mode by hitting Esc, then save and close the file with
When you start a terminal window next time, it should show you your new message! :-)
Should work on any Linux distribution.
@ambr: There's a "Subscribe" link in the first post, so you don't have to post something to subscribe any more.
Installing Google Chrome (BETA) under Linux
Not long ago, Google presented it's own webbrowser: Google Chrome. It was praised quite a lot, but one of the problems with it was, that it's not officially available for anything but Windows yet. However, there is a project to get it running on Linux and Mac OS X. It's not perfect, but it works. Here's how to install it: - Go to http://www.codeweavers.com/services/ports/chromium and download the newest version for your system.
- Install the file you just downloaded. If double clicking on it doesn't work, try this:
- On Debian or any deb-based system (like Debian, Ubuntu or Knoppix), open a console and direct to where the download is saved. Then enter
- sudo dpkg -i cxchromium_*
- On a rpm-based system (e.g. Fedora, openSuSE, Mandrivia,...), open a console and direct to where the download is saved. Switch to your root account with
Then enter
- On any other type of Linux distro, open a console and direct to where the download is saved. Switch to your root account with
. Then enter
- chmod +x cxchromium_*
-
./cxchromium_*
- On a Mac, just drag the .dmg file into your Applications folder
- Either start Chrome via an icon (if you can find one) or use the command
in a console window.
- Enjoy!
I admit, it's not that fast yet, as this is actually a windows build using wine (so you may have to install wine too - check your distribution to find out how to do that), but it works!
Tested on Ubuntu 8.04, but should work on most other systems too.
NOTE: If you're interested in a real version for Linux, you can register to receive information as soon as it's available here or here for Mac versions.
Useful key combinations
In the command line: - If you've started a command in the command and realise you don't want to complete it (e.g. copying loads of files to the wrong destination), there's a simple method to stop the command: Crtl + C
- If your screen is full of old output, you can easily clear it with Crtl + L
- To log out in a console, press Crtl + d. (Note: If this is a terminal emulator in your graphical environment, it will probably exit.)
- To jump within one command in the command line, use Crtl + A to jump to the beginning and Crtl + E to jump to the end.
In the graphical environment: - You want to switch to a console quickly? Maybe even without login on to your graphical environment? Easy: Use Crtl + Alt + F1 to Crtl + Alt + F4 (and sometimes more) to get a basic console. To change back, it's normally Crtl + Alt + F5, Crtl + Alt + F7 or Crtl + Alt + F9
- Your desktop environment has crashed? Doesn't happen very often, but it happens. The solution? Restart the X-Server with Crtl + Alt + Backspace
Hint: Sometimes when talking about key combinations on Linux, you read about the Super key. This is normally the Windows key of your keyboard.
Tested on Ubuntu, but should work on any Linux distribution.
Surfing the web from the command line
When we think of surfing the internet, it's usually combined with a graphical browser like Firefox, Opera, Konqueror, etc. However in some cases, you don't need that much or can't use a graphical interface. Does that mean, you can't surf the internet?
No, it doesn't. There are actually some pretty good command line browsers available. My favourite is w3m, but lynx and links are also quite popular choices.
So, how does this work? Basically, you just enter
to get here and then use your keyboard to navigate. To get help, press Shift+H. Some of my most used commands are: - u : Show the address a link points to
- Crtl+t : Opens a link in a new tab
- { and } : Switch between your tabs
- Shift+B : Go back in the browser history
- Shift+U : Enter an URL to browse to
- q : Quit w3m
- Shift+Q : Quit w3m without asking
Another tip: starting w3m with the option -F makes w3m automatically render frames. As I like it to do so automatically, I created an alias
(See one of the earlier posts to find out about aliases.)
This Tip was tested on Ubuntu and Debian, but should work on any Linux distribution.
Downloading from the command line
When you download something, you either do so via a browser or a programmed designed for downloading. I've already talked about command line browsers, now I'll talk about a command line downloader: wget
wget works pretty easily: simply type something like - wget http://mirrors.us.kernel.org/ubuntu-releases/intrepid/ubuntu-8.10-desktop-i386.iso
to download an Ubuntu 8.10 ISO for example. But wget can do much more than that.
For example, it can resume downloads. Say you started downloading that Ubuntu ISO, but had to cancel the download. Then you can continue it with - wget -c http://mirrors.us.kernel.org/ubuntu-releases/intrepid/ubuntu-8.10-desktop-i386.iso
It's that simple.
Of course, there are much more functions as well - check man wget to find out more.
This Tip was tested on Ubuntu and Debian, but should work on any distribution.
Viewing text files
If you want to view a text file in the command line, first choice is cat:
But this isn't always the best choice.
Say, you have a very long file and want to look at it from top to bottom. In that case, have a look at less:
You can quit viewing by pressing q.
If you only want to view the first 15 lines of a file, head would be the tool of choice:
Leaving out the -n 15 will show the first 10 lines of the textfile.
Now, you can also view the last 15 lines of a file of course - try tail:
The options are similar to those of head. However, there is a further very useful option:
will show any updates to the bottom of the file too.
Of course, you can combine these commands. For example - head -n 100 textfile | tail -n 50 - | less
will show you the lines 50 - 100 and allow you to scroll through them.
These Tips were tested on Ubuntu, but should work on any distribution.
Showing and editing system time
Basically any modern desktop environment will offer a clock and calendar of some kind, but you're not limited to those - you can get those in the command line too! - Current time and date
To show the current date and time as saved by the OS, call
To set that date, use something like - date -s "Wed Dez 03 21:38:59 GMT+1 2008"
(You'll have to be logged in as a superuser for this to work.)
This will set the date, but that setting will disappear with a system restart. To save it, you'll have to use the command
which will set the hardware clock to whatever the system clock is currently set to.
- Calendar
By simply entering the command
or
you'll see a calendar, displaying the current date. For the calendar of a complete year, use
(or whichever year it's supposed to be.) You can also display a different month than the current one:
If you want to see the previous and the following month too, try
If you want Monday to be the first day of the week (as opposed to Sunday), use
The date of easter for the current year can be called with
for western churches or
for Greek and Russian Orthodox Churches
If you want to know the number of the week, use
Note, that all dates are saved and interpreted as after the 1st Jan 1970, 00:00:00, so if you want to use a date prior to that, you'll have to use an alternative method.
These Tips were tested on Ubuntu, but should work on any distribution.
Comparing files
Sometimes, you want to compare two files and spot the differences. Of course, you can do that manually, but there's also the tool diff, which can automate this. Here's how you use it.
Say, you want to check what device name a usb pendrive gets. First of all, you make a list of the current devices:
Now, plug the device in and wait for a few seconds, so that the system can recognise the new device. Then run
You now have a list of the devices before and after plugging in your pendrive.
To compare the two, use
The output will be something like this:
So, the entries after ">" have been added in the "after" file. If you do it the other way round ( diff after before), you'll get
Here, the entries after "<" have been removed.
Of course, this tool can be very useful in other scenarios, especially programming.
This Tip was tested on Ubuntu, but should work on any distribution.
Looking at running processes and stopping them
When you want to look at what processes are running, there are three main command line programs: ps, top and pgrep. Here's how to use them:
This will list all running processes by all users. One interesting thing that we'll need later is the column PID.
This will display an updating screen which shows the processes that use up most CPU power with some further information.
This will list all processes that the user username is currently running, including their PIDs. If you want to filter for certain processes, you can use
instead (to filter out everything containing the word bash). These can be combined of course: - pgrep -l -u username bash
If you want to close a process, you can use the commands kill and pkill for that. Here's how they are used:
Now, that pid is the Process ID we noticed before. If you don't know the PID (or want to kill all processes with something specific in their names), use
instead.
What both of these commands will do is send those processes a signal saying something like "Hey, please abort." However, if those processes have truly crashed, then that won't work. You should certainly try that first, but if the process doesn't shut down, use the following:
or
This sends a KILL signal, that can not be blocked.
This Tip was tested on Ubuntu, but should work on any distribution.
Adding own scripts and binaries
Let's say, you wrote a little tool called myTool and the binary is saved in your home directory under ~/myTool/bin/ - you won't be able to run it if you're not in that directory or if you don't use the full path. This is because it isn't in the so called PATH variable. You can have a look at this PATH variable by calling
in command line - it may look something like this: - /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/real/RealPlayer
The directories listed here and separated by colons (":") are those, that are in the PATH variable and that you can therefore call from anywhere.
There are two realistic ways to add a command to the PATH variable: Add that tool to a directory, which is already listed or add a directory to the list. If this tool should be available to everyone using the system, the first option is best. The directory /usr/bin should be the best choice here in most cases. So either copy your tool there, create a link or write a little script, that will call your tool.
If only you want to use your tool, add the directory it's in to the PATH directory. For the current session, this command should do fine: - export PATH=$PATH:/home/user/myTool/bin
If you want to have it available permanently however, write that line into the .bashrc file in your home directory.
This Tip was tested on Ubuntu using bash, but should work on any distribution that uses bash. The syntax may be different for other shells.
logging on console
My first tip is about logging, especially logging system logs on 11. and 12. console like it is in gentoo. If we are using common linux logger syslog the way is add this lines to /etc/syslog.conf - # Log everything on tty12
-
*.* /dev/tty12
-
-
# Log kernel messages on tty11
-
kern.* /dev/tty11
this lines says that syslog will log system logs to 12. console and all kernel logs to 11. console
Now we need restart syslog - /etc/init.d/syslogd restart
or - /etc/init.d/sysklog restart
it depends on distribution you are used.
we can view the console by pressing alt + F12 for system logs or alt + F11 for kernel logs, if we are in GUI we must press alt + ctrl + F11 or alt + ctrl + F12.
for return to GUI we press alt + F7 becouse default console for GUI is 7 ;) advanced uninstall packages in slackware
if we want to remove some package on slackware we have to write whole name of package and it removes without asking. i solved this problem with very simple script. here it is: - #!/bin/bash
-
-
if [ -z $1 ]; then
-
echo "Missing arguments";
-
exit 0;
-
fi
-
-
PKG_DIR=/var/log/packages
-
-
for ARG in $*; do
-
PACKAGES=`ls $PKG_DIR | grep $ARG`;
-
for PKG in $PACKAGES; do
-
echo "Do you really want to remove $PKG (y|n) ?";
-
read ANS;
-
case $ANS in
-
y) removepkg $PKG > /dev/null;
-
echo "Package $PKG successful removed";
-
;;
-
*) echo "Skipping $PKG...";
-
;;
-
esac
-
done
-
done
we write this into file for example rempkg, copy this to /usr/sbin and give execute bit. - cp rempkg /usr/sbin/rempkg && chmod +x /usr/sbin/rempkg
console resolulution
My last tip is about freebsd, I hope this topic isn't only for linux :)
I use freebsd but wihout x windows system and I don't like big resolution what is used by default. So I compiled vesa support into the kernel for better resolution.
first step what we need to do is change directory to /usr/src/sys/i386/conf architecture select which you use. - cd /usr/src/sys/i386/conf
then we copy old config to new file.
add this line to the new config - options VESA
-
options SC_PIXEL_MODE
save & exit
change directory to /usr/src and compile new kernel - make buildkernel KERNCONF=VESAKERN
-
make installkernel KERNCONF=VESAKERN
-
reboot
after reboot we can show list of all resolutions by
for change resolution run this command - vidcontrol MODE_<NUMBER OF RESULUTION>
when we are definitely decided for resolution we can change it permanently by editing /etc/rc.conf and adding this lines
allscreens_flags="MODE_<NUMBER OF RESOLUTION>"
save & exit & reboot ;)
ps. I'm really sorry for my english but I'm not native english speaker so keep it in mind ;)
REGARDS,
vl4kn0
To run different window managers simultaneously
1) Take a new virtual console ( ctrl + alt + F1/F2/F3)
2) for X server Secession without window manager type "xinit -- :2"
3)from here we can run
a) "startkde" for KDE
b) "gnome-session" for GNOME
Most or all of these tips also work in the BSDs
Linux is not BSD Unix or Solaris but they are in the same family and most, if not all, of the tips here will work in those operating systems, too.
@drhowarddrfine
Thanks for that hint, I've changed the subject accordingly.
Greetings,
Nepomuk
Middle Mouse Button Auto-Scroll (Firefox)
I have one for you.
Coming from a long-time Windows background, I was very used to doing middle-button click and drag to scroll much quicker in Firefox. I was disappointed to find that this did not happen in Ubuntu. The fix is simple, though.
Navigate to about:config in Firefox (type that in your address bar, hit enter). Then search for 'autoScroll'. Double clicking the 'general.autoScroll' entry should change it's value from false to true. If not, you can manually edit it by right clicking the entry and then selecting 'toggle'.
Hey presto, you can now scrub through pages as quickly as you used to do!
your one line webserver - cat index.html | nc -l 80
to search for phrase from disk and replace back in (check if it works) - dd if=/dev/sda10 | sed 's/aaa/bbb/' | of=/dev/sda10
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Francesco Bochicchio |
last post by:
Hi all,
anybody knows if there is a (standard, portable) way to dinamically build
a list of parameters to call a C function? Something like va_start & co,
but to be used on the calling side?
...
|
by: Daniel Rudy |
last post by:
Hello,
On a x86 machine, what is the format of a pointer in C? I know for a
fact that the x86 p-mode uses a /selector:offset/ notation where the
selector is defined in either the GDT or LDT. ...
|
by: Gibby Koldenhof |
last post by:
Hiya,
I'm setting up some code in the spirit of Design Patterns, OOP, etc. All
nice and well, it handles pretty much all OO style things and serves my
purposes well. There's one last final...
|
by: John Friedland |
last post by:
My problem: I need to call (from C code) an arbitrary C library
function, but I don't know until runtime what the function name is,
how many parameters are required, and what the parameters are. I...
|
by: travolta003 |
last post by:
Windows XP tips and tricks. Learn how to bypass very common windows
problems, speed up your system and make it more reliable with useful
tips and tricks.
http://windowsxpsp2pro.blogspot.com
|
by: travolta004 |
last post by:
Windows XP tips and tricks. Learn how to bypass very common windows
problems, speed up your system and make it more reliable with useful
tips and tricks.
http://windowsxpsp2pro.blogspot.com
|
by: bartonc |
last post by:
I've decide to compile a bunch of your favorite tips and tricks for the Articles section. I found a post yesterday by Chrisjc that is a perfect example. I copied his post over to create Dealing with...
|
by: bartonc |
last post by:
I've decide to compile a bunch of your favorite tips and tricks for the Articles section.
Post your favorite tips and tricks here, in this thread, and I'll copy the best ones to a Tips and Tricks...
|
by: Frinavale |
last post by:
Edit
Many times we spend hours and hours trying to solve a problem. When we finally figure it out, we want to share it to keep others from suffering the same way!
That's why we have this "Tips...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |