Linux, OpenSource, Programming And Hacks

Sep 15, 2012

Some basic Terminal commands for ubuntu linux

Sep 15, 2012

What is sudo? - It stands for Super User DO and is a command that allows users to have root/super user access without logging as a root

APT-GET Commands

The apt-get is a very powerful command-line tool commonly used for updating the software sources (repositories) , upgrading existing installed software, installation and removal of new software. lets look at some common apt-get commands.

Updating and Upgrading software

This is a very common apt command that is used to update your software sources. It is the first command that you enter when you have installed a fresh ubuntu.

sudo apt-get update

upgrade command downloads and installs any newer versions of your installed software. make sure you run the above update command first so that the software sources are first updated and you get latest software.

sudo apt-get upgrade

Installing/Removing software

This command first downloads and then installs a new software. here we are installing a software called virtualbox. replace virtualbox with any other software you want to install. 

sudo apt-get install virtualbox

Now, to remove an existing software

sudo apt-get remove virtualbox

List all files/dirctories

The ls command lists all files and directories


If you want to see a long listing (detailed) use -l option

ls -l

The -a option will list all files including hidden files

ls -a

Creating a new file and folder

The touch command creates a empty new file

touch newfile

The mkdir command creates a new empty directory

mkdir newfolder

Add contents to a file

use the cat command with redirection '>' to add text to a file. Press Ctrl+D when you have finished adding text.
cat > myfile

View Contents of a file
use the cat command to view contents of an existing file. let's view myfile , that we created in the previous command
cat  myfile

Change Directory
with cd command you change your directory. by default you are in home directory. Let's change our directory to Desktop

cd Desktop
Note: linux is case sensitive so don't type 'deskop' but 'Desktop'.

To come back to your previous directory(home directory)
cd ..

the double dot means the parent directory


just the cd command will take you to your home directory from wherever you are.


Present working Directory
the pwd command shows your current directory with full path name


Delete a file
'rm' stands for Remove and this will Delete the file myfile Permanently so you won't be able to Restore it from Trash.

rm myfile

Copy a file
To copy files, you use the cp command. The following will copy file from home folder and paste it to Desktop.
By default you will be at your Home folder so you don't need to change the directory.

sudo cp abc Desktop

Move a file

to move a file to different location, you use the mv command.The following command will cut file from Home folder and paste it to Desktop

sudo mv abc Desktop


Info Commands

Software versions:
lsb_release -a  Distribution info
cat /etc/issue – current distribution and version
apt-cache showpkg packagename – packagename’s version and dependencies
uname -r - Linux kernel version
uname -a – all kernel details

Graphics card:
glxinfo – details about OpenGL, the Xserver, and your graphics card
glxinfo | grep direct – It will show if you have direct 3d rendering or not
glxinfo | grep vendor – graphics card vendor
lspci | grep VGA – specific graphics card model
glxgears – a simple 3d benchmark, prints frame rate to the terminal
xrandr – supported display resolutions

lspci | grep Audio – audio controller
aplay --list-devices – more audio device information

lspci | grep Ethernet – Ethernet controllers
ifconfig – networking interfaces, IP addresses, and more

cat /proc/cpuinfo – all processors, clock speeds, flags, and more
cat /proc/loadavg – processor load average for the last 1, 5, and 15 minutes
top – press C key to sort processes by CPU usage

cat /proc/meminfo – amount of RAM and swap, and how much is being used for what
free -m – total, used, and free memory shown in MB
top – press M key to sort processes by memory usage

Hard disks:
df -H – partitions, as well as their mount-points and usage in GB
sudo fdisk -l – all partitions, their device names, and positions on disk

USB devices:
lsusb – USB buses and attached devices

Even more:
lshal -m – monitor for hardware changes
lspci – all PCI devices
hwinfo --short – overview of all hardware, as well as more detailed info
lshw – another program for listing hardware
lshw -html | w3m -T text/html – lists hardware with HTML output in the w3m web browser
uptime – current time elapsed since last reboot, users, and load average

No comments:

Post a Comment