

| Beginners Start Here Fun With Linux Commands - including: Using your computer for an alarm clock - how to edit /etc/crontab General Purpose Commands File Ownership and Permissions File Compression System Administration Networking Putting commands together - | > >> apt Hardware Detection and Testing - hardware and software testing and diagnostics Internet and Downloads - btdownloadcurses, wget, youtube-dl Text Editors - gnu nano, gedit, kate, mousepad, vim |
| For Beginnners These days you don't have to learn Linux commands to be able to use Linux. Most Linux based operating nowadays have all the GUI programs you need to do almost anything. Learning how to use Linux commands is fun though, and there are still a lot of useful and time saving things we can do with Linux commands. The main thing to know is that you don't need to force yourself to learn anything and everything right away. Give yourself plenty of time. You'll be surprised how much you can learn without even trying. One hint that everyone should be aware of is that if someone (from a web forum maybe), recommends you run a Linux command, you should look up the 'man' page for the command to see what it will do before you apply it. The word 'man' in Linux is short for 'manual'. That's where we look up commands we want to learn how to use them better. To do that you open your terminal and type: man <name-of-command> The man pages are little like a dictionary or an encyclopedia, but for Linux commands. It's a good idea to learn how to read the man pages. They contain lots of really interesting information and can help you get the most out of Linux. Linux commands are a bit like ordering a hamburger, just a plain, bare hamburger is okay, but a hamburger with your own favorite combination of ingredients is a lot better. You might order your hamburger with onions, salad or coleslaw, ketchup or mustard, cheese, an egg, and so on. Linux commands are a lot like ordering a hamburger, they have lots of 'options', and these options make a big difference to what happens when the command is run. You can run Linux commands with no options, but it's a bit like ordering a plain hamburger - boring. If you want to get the most out of Linux commands, you need to be able to specify the right options, just like when you specify what you want in your hamburger when you order it. The man pages are for telling us what options are available for each command and what the options are supposed to do. The problem for new users is, the 'man pages' were written mainly by the programmers themselves, and they're fairly brief and concise. Most new users have a hard time understanding what the man page is trying to tell them. This creates a kind of recursive problem. The new user is the very person who probably needs to be able to access the information in the man page most urgently. Unfortunately, the man pages are full of strange words and concepts. For example, if the new user doesn't know what 'recursive' means, they will have no idea what I'm talking about right now. Most of the time we still need to try out the command and see for ourselves what happens with different options before we feel comfortable using that command. It takes time and practice to feel confident running Linux commands. The best place to start learning how to use Linux at the command line is from one or two of these great Linux tutorials, 'Terminal For Beginners' , by kryal of Ubuntu Web Forums would be a great help. It's a very informative thread, it's a Ubuntu Web Forum thread. Some Linux tutorials are more specific to other distros and some of the commands work a little differently, so it's nice to see an good all-Ubuntu tutorial, thanks Kryal! UNIX Tutorial for Beginners This one's about Unix, which is the language that Linux is based on. Linux uses unix commands, plus some extra ones that Unix might not have. This is the first one I began learning from, and I still refer to it often. There are a few things here that might not directly apply to Ubuntu, but it's a great tutorial. Linux Command.org Linux Online - Linux courses The Linux Tutorial A Hands on Guide by Machtelt Garrels Rute User's Tutorial and Exposition by Paul Sheer TLUG CS Student Linux Users Guide HowTO Ubuntu System by ajmorris These are just a few, there are plenty more you can google if you like. Terminal Most people will already know what a terminal is. In Ubuntu, you can find the 'terminal' by going 'Applications'-->'Accessories'-->'Terminal', and click on 'Terminal'. I find it handy to right-click on the accessories menu link for 'Terminal', and click 'Add this launcher to panel. That will add an icon for it on our top panel (or tool bar if you are an ex-windows user) so it will be quicker to find it from now on. Terminal is something we all use a lot. When your terminal is open you can type Linux commands after the prompt. A Linux terminal prompt looks some thing like this, Code:
'@bookpc' means I'm at a computer named 'bookpc', '~', which is a symbol called a 'tilde', is a shorthand way of saying I'm working in my /home/username directory right now. '$', is the prompt, and it's a dollar sign to indicate that I have a BASH shell We can type commands after the prompt: $ and when we press our 'enter' key we expect our computer to do something, (run the command). Opening a 'tty' With Ubuntu booted up, try pressing 'Ctrl' + 'Alt' + 'F1', (or any other F key from 2 to 6), and that will give you a 'tty'. Not so many new users will know how to get a 'tty' and it can be quite useful. A 'tty' is something like a terminal. You can log in with your username and password then, and practice Linux commands there. If your gnome desktop (Graphical User Interface) doesn't load, or if it ever freezes, sometimes you can't open a terminal, but you might be able to open a 'tty'. Most of the time, I use a terminal for my Linux commands but it's good to know that a'tty' is there for an emergency.
Press F7 to go back to your Desktop. |
Some Fun With Linux Commands
W3M, the terminal based web browser This is kind of neat open a tty or a terminal and type the following, Code:
Type 'q' for quit, to exit w3m, then 'y' for yes. When you are finished using the tty, type 'exit' to log out of the tty.,just press 'Ctrl' + 'Alt' + 'F7' to return to the normal G.U.I. There are tty's for F2, F3, F4, F5, and F6. (When those keys are pressed simultaneously with 'Ctrl' + 'Alt' 'Ctrl' + 'Alt' + 'F7' keys return you to GUI mode. 'bc' the terminal based calculator You can also type 'bc' for a terrific text-mode calculator that can handle a lot of digits. One of the great features of this calculator is you can press your 'up arrow' key to scroll back to previously entered operations. Very handy and convenient. You will discover more about bc when you start practicing with it. When done, type 'quit' to get back to your command prompt.
cal is short for calendar Another little trick is to type 'cal' for a calendar. Today's date will be highlighted. Code:
cal -y will give us a calendar for the whole year, Code:
If we type the whole word 'calendar', (as a command), we will be given a list of historical events for today's date, Code:
If we type 'date' as a command, we will be given the current date and time.
TIP: You can change the color of your terminal by right-clicking on an open terminal window and then click 'edit current profile', and in the 'Colors' tab, remove the check mark from the square for 'Use colors from system theme'. Then you can choose your own text color and background color for your terminal. If that isn't enough for you, you can click the 'effects' tab, and choose a background image, or select the radio button for 'transparent background', and even set the opacity with the slider under there. espeak - make your computer talk to you Code:
Try it! You can type any words or sentences after the 'espeak' command and your computer will repeat the words you typed through the speakers. Use your computer for an alarm clock 1. Learn how to play a sound file from the command line (i) totem media player can be started from the command line.
(ii) Use totem to play a sound file from your terminal,
(iii) be ready to copy the command you used to play the sound file,
2. Edit /etc/crontab
The following command will open my text file called /etc/crontab with my text editor 'gedit'.Code:
my /etc/crontab file before editing:
There are four commands in here already. These are for running anacron scripts in the directories cron.d cron.daily, cron.weekly and cron.monthly. Those control regular operating system functions. It would be best to leave those alone unless you know what you are doing. Now I'm going to edit my /etc/crontab file by adding a new line of my own, but first I need to explain the meaning of the figures are in each of the columns. We really can't see any columns there at all. If it was a spreadsheet we would be able to see the columns. Since it's only a plain text file, they're not so easy to distinguish. We need to know they're there.
So if I want to play an .ogg sound file early every morning to wake me up in time to get ready for work, I will add a line like this,
15 4 * * * herman export DISPLAY=:0 && /usr/bin/totem /home/herman/Music/track01.ogg That line means at 15 minutes past 4 every day of (the) month, every month, every day of (the) week, my computer will run the program called /usr/bin/totem, which is to open the file named /home/herman/Music/track01.ogg The 'export DISPLAY=:0 &&' part is special. That part of the command is only needed because totem is really a GUI application, and therefore we need to tell crontab which X-server to use. Thanks to henriquemaia for this how-to: crontab: How to run GUI programs with cron. I originally made this how-to with the program called 'play', which was a terminal based sound player, so I didn't need the 'export DISPLAY=:0 &&' part, but the 'play' program doesn't seem to exist anymore. I tried mplayer which is another terminal based media player which is supposed to be good. Mplayer works from terminal but unfortunaltely I couldn't get mplayer to work from crontab. my /etc/crontab file after editing:
(Yours won't be in color of course, and mine isn't either, the highlight colors shown here are only to make it easier to show you what I did). NOTES: 1. To get the command right, it's best to run it from a terminal first, and then copy your command from there. Sometimes there are some strange syntax peculiarities in some of the filenames, especially if they're not native to Linux. 2. The program named 'totem' is located in /usr/bin. I recommend telling crontab the exact, complete file path for the program just to make sure, but it will probably still work okay if you just type 'totem' without the whole filepath. 3. You should test run your new crontab by setting the time for a few minutes from now and waiting to see if the file will play to be sure it will work as expected. Your cron job needs to be set for at least two minutes ahead of time to give the cron daemon time to register the new cron job. The cron daemon runs every minute to scan the files for changes. 4. To check and see if the cron daemon is running, try this command, Code:
Once you get the knack of using crontab, it is possible to do much more with crontab than this. You can get crontab to do almost anything, automatic backups, send or receive email... As a matter of fact I bet I can even get my computer to turn my kettle on for me five minutes before it wakes me up in the morning! :) Take a look at this,
Now if I somehow place a switch for the kettle where the CD-ROM drawer is likely to strike it on its way open... : ) Actually, there is a website already devoted to having Linux make coffee, it's quite a sophisticated website too, 'Linux DOES make coffee and it tastes good as well!', Coffee Making. And not only that, there's even 'Life After Coffee' too! I really like that Coffee Making tutorial, but I have a problem. Where I live it would be hard to get the right electronic parts to make a relay switch or a triac for my computer's parallel port. I wanted to see if I could get my computer to make coffee for me using low cost, common everyday household items that anyone, anywhere would have lying around or could easily get ahold of.
If you want to see photos of my set-up, I have uploaded them to my gmail picasa site, click this link to take a look, http://picasaweb.google.com/herman543/HowMyComputerMakesCoffee Now back to business, here's a link to the Official Ubuntu Wiki's How-to for cron, CronHowto It says there that it's better to use the other method for setting up a cron job, the crontab command. I wanted to start with this /etc/crontab method just explained though, because it's a little simpler for beginners. To use cron, you need to learn only a little something more, how to use nano text editor. It's not hard to use nano, but I wanted to take things one step at a time and not hit new users with too many things at once. Here's a link to my 'Back up and Restore Page', where I have an example of the use of crontab to make regular backups for email and other stuff. Back Up and Restore. Now that I have shown you how you can make a cron job by editing /etc/crontab, it's only two more steps to learn to use the crontab command and nano instead, and do things the recommended way. Another way to set alarms in Ubuntu is by configuring reminders in Evolution's Calendar to run a program, see Memos, Tasks and Calendar Appointments. |
| Camera Tricks With GNU/Linux Did you know that some digital cameras and probably most webcams can be controlled by Linux? That means we can use our Ubuntu computer to tell the camera when to take pictures or video. In other words, it's possible to use Ubuntu for time lapse photography. Time lapse photography is really cool. Just try a google search for a few examples of time lapse photography and I'm sure you'll be impressed. I first read about this at the following website, A Webcam Server with Linux, and I think that most people would find that entire website very interesting and helpful, especially if you enjoy having fun with Linux using the command line. After reading Professor Marzolla's excellent website, (linked above), I was inspired to try something like that myself, but with a little bit of a difference. For my purposes I wanted to be able to take pictures and at the same time use my USB GPS receiver and have each photo geotagged in real time, (immediately after each photo is taken). Here is a link to a thread in Ubuntu Web Forums where I posted details about that, geotag webcam images. In the course of my research into time lapse photography, I also learned that it's possible to 'pan' the camera, (have it turn a little in between shots), and when this is done well, it becomes a special effect which adds to the quality of the finished product. To acheive this, I read that it is possible to use a program in called pyrocket to control a toy rocket launcher with a camera on it instead of the cannon or missile launcher. |
| Links that explain all about specific commands The umount Command - The Linux Information Project The head Command - The Linux Information Project The useradd Command - The Linux Information Project Checking disks for errors using the badblocks command - Ubuntu Magnet Learn The DD Command Revised - Linux Questions.org - by awesome machine Genisoimage – Creates ISO-9660 CD-ROM filesystem images - Debian Admin |
| awk '!a[$0]++' ./all_roads.csv > ./all_roadsII.csv |
copy
data containing duplicate lines from a file and creat a new file
without any duplicate lines, even if the duplicated lines are
non-consequtive |
| ls | a list of the files and directories inside a directory, in alphabetic order running across the page (horizontal) |
| ls -a | show a list of the all (including invisible) files and directories inside a directory, in alphabetic order running across the page (horizontal) |
| ls -l | show files and directories in a long list, vertically listed (columns), in alphabetic order, including ownership and other details of each file |
| ls -lX | show files and directories in a long list, (columns), sorted by filename eXtension, including ownership details of each file |
| ls -lS | show files and directories in a long list, (columns), sorted by file Size, including ownership details of each file |
| ls -lt | show files and directories in a long list, (columns), sorted by last modification time, including ownership details of each file |
| ls -lh | show files and directories in a long list, (columns), with humanly readable file sizes in alphabetical order, including ownership details of each file |
| cd | change directory |
| cd /usr/local/apache | go to /usr/local/apache/ directory |
| cd~ | go to your home directory |
| cd- | go to the last directory you were in |
| cd.. | go up a directory |
| cat | short for 'catalog' - print file contents to the screen |
| cat /boot/grub/menu.lst | cat the contents of /boot/grub/menu.lst to your screen |
| tail | like cat, but only reads the end of the file |
| tail /var/log/messages | see the last 10 (by default) lines of /var/log/messages |
| tail -f /var/log/messages | watch the file continuously, while it's being updated |
| tail -200 /var/log/messages | print the last 200 lines of the file to the screen |
| more | like cat, but opens the file one screen at a time rather than all at once |
| more /usr/sbin/update-grub | browse through the usr/sbin/update-grub file. hit Space to go to the next page, q to quit |
| cp | the copy command - make another copy of a file |
| cp filename filename.backup | copies filename to filename.backup |
| cp -a /media/oldinst/home/* /media/newinst/home/ | copies all files, retaining permissions from one directory to another |
| cp -Rav *. ./newdir | copies all files and directories recurrsively in the current directory INTO newdir |
| mv | the move command - move or rename a file |
| mv oldfilename newfilename | move a file or directory from oldfilename to newfilename |
| rm | delete (remove) a file |
| rm filename.txt | deletes filename.txt, will more than likely ask if you really want to delete it |
| rm -f filename.txt | deletes filename.txt, will not ask for confirmation before deleting |
| rm -rf tmp/ | recursively deletes the directory tmp, and all files in it,
including subdirectories. BE VERY CAREFULL WITH THIS COMMAND!!! |
| echo 'hello world' | The echo Command - linfo.org prints messages in the terminal screen, useful for bash scripting for informing users UNIX / Linux echo command examples - nixCraft Linux Forum |
| find | You can use this command to search for files if you know the name of the file you're looking for |
| sudo find / -name oo-welcome.odt | finds files with the name 'oo-welcome.odt' |
| find documents/textfiles | grep dianne | looks for all the files in /home/herman/documents containing the word 'dianne' |
| find /media/Windows -iname "*.jpg" -print | finds all .jpg images in Windows and shows you the list of thier names |
| find /media/Windows -iname "*.jpg" -exec cp {} rescue \; |
finds all .jpg files in /media/Windows and copies them to a directory named rescue |
| find /Pictures -iname "*.jpg" -exec mv {} Pictures/jpg \; | for sorting your files, rounds up all .jpg files in pictures and moves them into one directory |
| locate | It's better to use 'locate' instead of 'find' , because 'find' thrashes your hard drive. |
| sudo updatedb | Create or update the database used by the locate command A cron job is run by default in Ubuntu to update the locate database every night |
| locate oo-welcome.odt | finds files with the name 'oo-welcome.odt' |
| grep | looks for patterns in files |
| grep root /etc/passwd | shows all matches of 'root' in /etc/passwd |
| grep -v root /etc/passwd | |
| grep --color -i -n -o -R -e grep . | searches for files containing the word 'grep', in entire home directory. |
| grep --color -i -n -e ffmpeg .bash_history | search your .bash_history file for the word 'ffmpeg', and print the lines. TIP: You can use this to remind yourself of all ffmpeg commands you used in the past. |
| grep --color -i -n -C3 -e grep ./file.txt | searches the file 'file.txt' for the word 'grep', prints 3 lines of context |
| grep -A 100 'End Default Options' /boot/grub/menu.lst | |
| wc | word count |
| wc -l filename.txt | tells how many lines are in filename.txt |
| which grub | will return the results of where a file named 'grub' is found |
| file /usr/sbin/grub | the file command tries to find out what kind of file a file is by looking at it's content. |
| file /usr/sbin/* | prints out a list of all files/directories in a directory, in this example, /sbin directory |
| stat filename | prints out a lot details about a file such as size, last access time, mod time, changed time, etc. |
| cmp file1 file2 | The cmp command compares two files byte-by-byte and displays the first occurrence where the files differ. |
| cmp file1 file2 -l | command compares two files byte-by-byte and displays a long list of occurrence where the files differ |
| diff file1 file2 | compares two files, reporting all differences, similar to the cmp command, but the output is more verbose |
| comm filename1 filename2 | The comm command compares two sorted files and displays the instances that are common. The display is separated into 3 columns. column 1 displays what occurs in first files but not in the second column 2 displays what occurs in second file but not in first column 3 displays what is common in both files |
| ln | create's "links" between files and directories |
| ln
-s /usr/local/apache/conf/httpd.conf /etc/httpd.conf | Now you can edit /etc/httpd.conf rather than the original. changes will affect the orginal, however you can delete the link and it will not delete the original. |
| touch | create an empty file |
| chmod | changes file access permissions. The set of 3 go in this order from left to right: USER - GROUP - ANYONE Here's a table for quick reference, the numbers 1 to 7 is this table are to tell you what numbers to use in your chmod command. The first number is the file owner's permission, and the second and third numbers set the group and other's permissions.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo chmod 644 webpage.html | chmod 644 : the owner can read and write to this file but everyone else can only read it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo chmod 700 private_file | chmod 700 : the owner can do anything with this file, but no-one else is allowed to see it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo chmod 755 myscript.sh | chmod 755 : to make scripts work they need to have execute permissions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sudo chmod 777 public_file | chmod 777 : anyone is allowed to do anything with this file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chown | changes file ownership permissions. The set of 2 go in this order from left to right: USER - GROUP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chown herman myfile.txt | changes the owner of the file to herman | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| chown herman.herman myfile.txt | changes the owner to herman and the group of the file to herman |
tar -cvvf stuff.tar dir/ tar -xvvf stuff.tar | tar Used for creating and extracting .tar and .tar.gz files, 't.a.r.' is short for 'TapeARchive', (was originally used for cassette storage media). create a tarball of all files in the named directory called stuff.tar (quick - no file compression, just an archive) extract the named directory from a tarball called stuff.tar |
| tar -czvvf stuff.tar.gz dirname tar -xzvvf stuff.tar.gz (or .tgz) | create a tarball of all files in the 'dirname' directory and call it stuff.tgz (with file compression) (.gz is faster than bz2 but gives less compression). extracts the files inside stuff.tar.gz |
| tar -cjvvf stuff.tar.bz2 dirname tar -xjvvf stuff.tar.bz2 (or .tbz2) | create a tarball of all files in the 'dirname' directory called stuff.tbz2 (with extra file compression) (.bz2 is slow and gives more compression than .gz). extracts the files inside stuff.tar.bz2 |
| zip files.zip file1 file2 file3 unzip filename.zip | compress the three files, display the rate of compression of each file, and store them in files.zip decompress a (*.zip) file zipped with a DOS compatible compression utility. |
| gzip filename gzip -d filename.gz | compress filename and turn it into a *.gz file Decompress the file, extract it |
| zip filename gunzip filename.gz bunzip2 filename.bz2 | compress filename and turn it into a *.z file decompress a *.z or a *.gz file decompress a *.bz2 file links: File Compression - Quick explanation, and File Compression Tools For Linux - Another explanation with just a few more details. |
| lsb_release -a | finds out what version of Ubuntu you're using |
| last | shows who logged in and when |
| last -20 | shows only the last 20 logins |
| last -20 -a | shows last 20 logins, with the hostname in the last field |
| w | shows who is currently logged in and where they are logged in from |
| who | This also shows who is on the server in an shell |
top | top shows system processes, memory information,
uptime and other useful info in a live table then type Shift + M to sort by memory usage or Shift + P to sort by CPU usage To find and 'kill' a runaway process |
du -sh du -sh * | du shows disk usage. shows a summary, in human-readble form, of total disk space used in the current directory, including subdirectories. same thing, but for each file and directory. helpful when finding large files taking up space |
| ps ps U username ps aux ps aux --forest | ps is short for process status, which is similar to the top command.
It's used to show currently running processes and their PID. A process ID is a unique number that identifies a process, with that you can kill or terminate a running program in your computer (also see kill command). shows processes for a certain user shows all system processes shows all system processes like the above but organizes in a hierarchy that's very useful! |
| kill kill 10550 kill -9 431 | terminate a system process kill process number 10550 kill process number 431, (process number from ps command) Use top or ps ux to get system PIDs (Process IDs) EG: PID TTY TIME COMMAND 10550 pts/3 0:01 /bin/csh 10574 pts/4 0:02 /bin/csh 10590 pts/4 0:09 APP Each line represents one process, with a process being loosely defined as a running instance of a program. The column headed PID (process ID) shows the assigned process numbers of the processes. The heading COMMAND shows the location of the executed process. |
| sudo reboot sudo shutdown -h now sudo shutdown -h +3 sudo shutdown -h 20:00 | reboot the system shut down the system (halt) right now! You can us -h for 'halt' or -r for 'reboot'. shut down the system (halt) after three minutes, warning messages are given to allow users time to close programs shut down the system (halt) at 8 pm, warning messages are given to allow users time to close programs |
| sudo lshw -C network | for information about network hardware |
ssh -p 223 herman@192.168.0.160 | ssh stands for secure shell, you use it for remote control of a computer with ssh server installed. connect to a computer running an ssh server at port 223, username is 'herman', IP address is ' 192.168.0.160' |
scp -P223 commands herman@192.168.0.160:commands scp -P223 herman@192.168.0.160:/home/herman/test_results . | scp stands of secure cp (copy), it's the name of a protocol/program for copying files across a network this copies the file 'commands' from silver laptop (remote machine) to bookpc. (note the dot .) this copies the file 'test_results' from bookpc to a remote computer (silver laptop). Where: silver laptop is the computer we're sitting in front of, port 223 is the port in bookpc that's configured for SSH, and the bookpc'sIP address is 192.168.0.160 |
| wget -q -O - http://whatismyip.com/automation/n09230945.asp && echo -en '\n' | display your external IP address for the router (internet) |
| ifconfig | grep -Po "inet addr:.+Bcast" | grep -Po '(?:\d{1,3}\.){3}\d{1,3}' | display your internal IP address for the computer (in the LAN) |
| ping -c1 -a -b -v 192.168.0.18 | finds out if there's a computer listening at IP address 192.168.0.18 |
| sudo tcpdump -c5 -vvv -n | listen on network and see who's pinging you |
| ifconfig ifconfig | grep 'inet addr:' | display network information for the host computer (including IP address) display IP address only |
| netstat netstat -an netstat -rn | shows all current network connections. shows all connections to the server, the source and destination ips and ports. shows routing table for all ips bound to the server. |
| netstat -an | grep 21
nc -zv <server-ip> 21 |
You may run this command in the server to check whether it's listening at port 21. You might use the 'nc' command from another Gnu/Linux computer, (replace <server-ip> with the server's IP address), to check the server to see if 21 port is reachable. |
| nmap -T Aggressive -A -v 10.1.1.* | scan LAN in address range 10.1.1.* to see what machines are in the network and gather information Warning: may be misinterpreted as an attack by some firewalls, do not use in corporate environments without permission from the network administrator. |
| How to keep a computer from answering to ping?(#18) a simple "echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all" will do the trick... to turn it back on, simply "echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all" | Firewall - iptables commands iptables -I INPUT -s IPADDRESSHERE -j DROP : This command stops any connections from the IP address iptables -L : List all rules in iptables iptables -F : Flushes all iptables rules (clears the firewall) iptables --save : Saves the currenty ruleset in memory to disk service iptables restart : Restarts iptables |
| sendEmail -f user@bigpond.net.au -t user@bigpond.net.au -o message-file=hello.txt -v -s mail-hub.bigpond.net.au | Email a text file from the command line (useful for scripting purposes) Where: 'hello.txt' is the name of a text file Where: user@bigpond.net.au is the email address of the sender Where: user@bigpond.net.au is the email address of the recipient Where: mail-hub.bigpond.net.au is the name of the mail server |
| command1 ; command2 | run command 1 and then run command 2 |
| command1 && command2 | run command1 and if successful, run command2 |
| command1 | command2 | read output from command1 and write it to command2 as input |
| file < command | read from a file and write the words to a command as input |
| command1 > file | read output from command1 and write it to a file if a file with the same name exists, overwrite it |
| command 1 >> file | read output from command1 and write it to a file, if the file already exists, preserve the existing data and append to it, if the file does not already exist then create a new file |
| command1 || command2 | run command2 if command1 fails |
| When
you have an installed operating system with all of your favorite
software added, you might want a list of the programs you installed so
you can easily install the same ones again in case you ever need to
re-install for some reason. This is only good for installing in the same version, not for upgrading to a newer version of Ubuntu. |
| http://www.math-linux.com/spip.php?article80 http://www.cyberciti.biz/tips/linux-get-list-installed-software-reinstallation-restore.html | Before you re-install, if you want a list of added software so you can install the same packages again in the new system. |
| sudo dpkg --list >> installedI.txt | You might run this command on a fresh installation and then keep a copy
of the output file for the future. |
sudo dpkg --list >> installedII.txt | This command will output another list of all installed packages to a text file and call it installedII.txt. |
| diff installedI.txt installedII.txt >> addedsoftware.txt | Now you can run the diff command on the two files to get a list of all added software |
| sudo dpkg --set-selections < addedsoftware.txt | Then, run this command |
| sudo apt-get dselect-upgrade | ... and finally, this one. |
| Installed .deb packages are stored in /var/cache/apt/archives, and you can make a backup of all the packages in /var/cache/apt/archives and paste it into another /var/cache/apt/archives in another installation of the same version of Ubuntu so you won't have to re-download the same packages again from the internet. |
| sudo apt-cache showpkg hdparm | less |
| dmesg > boot.messages | the dmesg program helps users to print out their bootup messages - possibly useful to identify a hardware issue which may be causing problems during boot-up |
| cat /var/log/syslog | less | if your computer shuts down suddenly and unexpectedly - you should check your logs to see if a hardware problem was the cause |
| cat /var/log/messages | less | if your computer shuts down suddenly and unexpectedly - you should check your logs to see if it's a hardware problem was the cause |
| cat /var/log/kern.log | less | if your computer shuts down suddenly and unexpectedly - you should check your logs to see if it's a hardware problem was the cause |
| cat /var/log/Xorg.0.log | less |
for diagnosing xserver problems for your video display |
| sensors | displays temperatures, voltages, fan rpm - HOW TO: Install and configure lm-sensors |
| sudo hddtemp /dev/sd*1 | displays temperatures of all hard drives containing a partition number1 |
| sudo dmidecode | motherboard and BIOS information - very good! :) |
| sudo dmidecode -t baseboard | just the motherboard info |
| sudo dmidecode -t memory | just the memory info |
| cat /proc/cpuinfo | gives information about what kind of CPU your PC has |
| cpufreq-info | if installed, this program provides info about your CPU frequency |
| lspci | hardware information - PCI bus |
| sudo lspci |grep [Aa]udio |
identify the audio controller |
| sudo lshw | less | lists all hardware |
| sudo lshw -C disk | Lists all hard disks and CD/DVD drives |
| sudo lshw -C network | gives information on your network card(s) |
| lsscsi | if lsscsi is installed, lists scsi hard disks |
| lsusb | Lists all usb devices |
| hdparm -tT /dev/sda | measure the read speed performance of the first hard disk |
| iostat -p /dev/sda | display information about disk activity (useful for flash memory) |
| iostat -kdx /dev/sda | display information about disk activity (useful for flash memory) |
| pidstat -d 2 | watch which programs are writing to disc (useful for flash memory) |
| cdrecord -checkdrive dev=/dev/scd0 | gives details about the CD-DVD drive |
| sudo smartctl -a /dev/sda >> harddisk.report | checks on the condition of a hard disk drive and prints the output to a file |
| sudo badblocks -sv /dev/sda2 >> badblocks.report | check a hard disk partition for bad blocks and write information to a report |
| sudo badblocks -sv /dev/sda2 10000000 | check just the first 10000000 blocks of a partition, (just a sample), to save time |
| sudo badblocks /dev/sda -w -s -p 5 | !!! securely erase all data from a hard drive while checking for bad blocks !!! |
| sudo lshw | sed -n '/*-memory/,/*-pci/p' | head -n -1 | gives a description of the computer's memory modules |
| iwconfig | find information about wireless networking card |
| iwlist scan | If your wireless network card is working, this command should find your wireless network and tell you all about it |
| aplay -l |
lists all PLAYBACK Hardware Devices (sound cards) |
| xdpyinfo | X-Server information |
| sudo apt-get install xresprobe sudo ddcprobe | to install xresprobe, (so we can run ddcprobe) displays X-Server info |
| lspci -x | grep -i "vga\| display" | more X-Server info (video card) |
| lsdev | if procinfo is installed - advanced |
| lshal | advanced , verbose |
| btdownloadcurses karmic-netbook-remix-i386.iso.torrent | commandline bittorrent - you may need to install bittornado for this to work |
| wget http://www.examplefile | download stuff with wget especially useful for large downloads (without any file corruption, even if the connection is interupted), or for writing scripts to automatically download a whole list of items (while you sleep). |
| sudo apt-get install youtube-dl | You can install youtube-dl to download youtube video's. |
| youtube-dl <url> | Then after this you can download most youtube videos by using this format in terminal. |
| gksudo gedit /boot/grub/menu.lst | gedit is the default text editor for gnome in Ubuntu - Tips for using Gedit Text Editor |
| kdesu kate /boot/grub/menu.lst | kate and kwrite are the default text editors for KDE in Kubuntu |
| sudo mousepad /boot/grub/menu.lst | mousepad is the default text editor for XFCE in Xubuntu |
| sudo nano /boot/grub/menu.lst nano | nano is the excellent command line text editor! You may someday need to use a command line text editor to rescue a broken system with no GUI. See Getting Started with GNU nano Text Editor, or just open nano and press ^g for the help menu, ('ctrl'+'g'). NOTE: the '^' (caret symbol) stands for the 'ctrl' key. |
| vim /boot/grub/menu.lst vim :help :q | vim (vi improved), is another editor with lots of features, Vim Documentation - sourceforge and/or, to learn how to use vim: open vim type :help :q to exit |
| Getting Started with GNU nano Text Editor The GNU nano text editor can be used to edit vital operating system files from a command line interface. Knowing how to use the GNU nano text editor might be important to you some day, it can get you out of a tight situation. If someday you can't boot normally because of a wrongly edited system configuration file, you may be able to boot into 'rescue mode' instead, (from GRUB). Once in 'Rescue Mode', you can open a root shell. From there you should be able to open the file with nano and edit your mistake to easily fix your problem. Don't wait for an emergency before starting to learn to use nano, start practicing with it now, it's easy. Then you'll know how to use it when you really need it. Knowing how to use GNU nano may save you the need for re-installing your operating system someday. GNU nano is also the text editor we use for configuring crontab to run a program automatically at a certain time and date, see Configure 'crontab'. To open Nano and create a new file, Code:
More often, you will be opening a file that already exists. For example, I can open my /etc/fstab file in nano and edit it, Code:
The instructions for how to use nano are already built into it, all you need to do is look at the help menu across the bottom of the screen.
TIP: The 'carat' symbol looks like a Chinese hat: ^ The carat symbol is shorthand for the 'Ctrl' key on your keyboard. For example, if you want to see the help file for nano, press the 'Ctrl'+ 'G' keys on your keyboard. When you are finished reading, press 'Ctrl' + 'X', (to exit). Links: GNU nano Home Page Nano Basics Guide - Gentoo Linux |
| Tips for using Gedit Text Editor Gedit text editor is extremely simple to use, but it's more than just another boring text editor, most people overlook a few it's wonderful features. Next time you have gedit text editor open, take a look in 'Edit'-->'Preferences'.
The 'Insert Date and Time function from the 'Edit' menu is one I use a lot. This makes it easy to use Gedit for keeping a diary or log book. ================================================================================ COOL IDEA: Did you know that you can use the 'grep' command to pull information out of a diary or log book into a .csv file which can then be opened with Open Office.org spreadsheet? To make use of this cool idea, you need to plan ahead and make the diary entries that you will later want in your spreadsheet in '.csv' format. 'csv' stands for 'comma separated values', and when a plain text .csv file is opened with a spreadsheet program, each column in the spreadsheet will be determined by where you place commas in the .csv file. Another thing you should keep in mind is that non-numerical values should be enclosed in "double quotation marks". More info: Comma Separated Values -Wikipedia Another trick is to use keywords like 'expenses' for a main heading and a second keyword like 'petrol' as a subheading to designate the type of expense. Later, you can use the grep command on either of those two keywords or some other keyword to bring up all the lines that contain the information you're looking for. The rest of my diary can be filled up with all sorts of irrelevant information and stories. For example, I will make all records of petrol (gasoline) purchases under the headings of 'expenses' and the subheading 'petrol' in my diary. I will make the entries in .csv format, using copy and paste to keep the columns all the same. example: '2006_log.txt',
Some day when I want to do some accounting, I can use the grep command to pull the relevant information from between all the other lines in my diary,
Example of .csv file's contents,
The .csv file can be opened with any spreadsheet program for further processing. I could instead use the grep command with the keyword 'Expenses', to make a .csv file for all of my expenses recorded in my diary, or I could use some other keyword such as 'Entertainment' to gather up all of my entertainment expenses. TIP: If you're not sure how to make lines in .csv format, try working in reverse, and make an example spreadsheet first with the columns you will want to see later. Then use 'Save As', from the 'File' menu, and choose to save your spreadsheet as a .csv file. Then you can open the .csv file with Gedit and copy an example line to your diary. Once you get started, keep to the same columns by copying and pasting an earlier entry and then editing that each time you want to make a new entry. TIP: Gnumeric Spreadsheet can be installed in Ubuntu and is very capable when it comes to working with .csv files, I prefer Gnumeric Spreadsheet for this purpose. |