Ubuntu Tips/Useful things for new Linux people

Reduce all that typing, use the * and ~ command.

As most of you know * is a wildcard, the cool thing is it can be applied virtually anywhere in the Linux Shell. It’s great for being lazy when you don’t want to complete a whole file name.

sudo nano /etc/apache2/sites-enabled/*

That command would edit the sites-enabled file, it is named ( at least on my server ) something strange like “000-default” and instead of remembering that, just put part of it. And a even more known thing is to use a ~ for your home directory, cool thing is you don’t even need to keep it in /home for it to find it.

cd ~/Pictures/May*9

That command would change directory into Pictures in your home directory and go to the folder that starts with May and ends with 9, such as May 2009

Don’t wait for a command to finish, just list them all at once with &&

sudo apt-get update && sudo apt-get upgrade

The command right there is a great command that simplifies Ubuntu updates to just one line, instead of updating ( finding out what needs to be upgraded ) and acctually upgrading the packages. These commands can really be piled on, like yesterday I used the following:

wget http://localhost:8080/ && cat index.html && rm index.html

I would download a file, print it out, and delete it. All in one command. && is great.

sudo mkdir /media/Data && sudo mount /dev/sdc1 /media/Data

Stop scanning through all that output, find it quickly with grep

This one took me a long time to understand ( not sure why ) but whenever your searching for something in output, just add a “| grep zzzz” at the end to find zzzz. Here is a real life example:

sudo netstat -tupan | grep 8080

That command would look at what program is using port 8080, or another example:

ls -Ra ~ | grep file.txt

That would list all the files in your home directory, ( the R is for recursive so it goes through all the folders in there not just the base one and the a is for all files, even hidden. ) and it would print out anything it finds that has “file.txt” in it.

Important Options on Important Commands

  • ls -l lists files with there permissions
  • sudo -i become root
  • cp -r, mv -r, ls -R, etc. Recursivley do something ( look through all the folders, not just the starting folder )
  • any command with -h -h or –help is normally the help output and is almost always there.
  • almost any command with -v verbose tells you everything it is doing, great for debugging

Great Commands

  • cat read a file without entering it, eg cat file.txt would output the contents of file.txt
  • touch create a file without entering it, eg touch file.txt creates file.txt
  • “echo ‘text here’ >> file.txt” adds ‘text here’ add the bottom of file.txt, can also use with commands like lshw >> lshw.txt
  • lshw -html >> lshw.html lists your hardware with lots of details in a neat html file.
  • sudo start/stop/restart servicename like sudo stop mysqld stops mysql

Other Random Things:

  • “.” is the present directory, just the period, like cp /etc/apache2/ ./ would copy everything in the apache2 folder to the present directory
  • “..” or “../” is the upper directory, apache2′s would be /etc and /bin’s would be / ( great for cd ../ )
  • The “d” at the end of things like sshd or mysqld normally stands for daemon
  • cron schedules things to run at certain times
  • Use public/private keys
blog comments powered by Disqus