Showing posts with label linux commands. Show all posts
Showing posts with label linux commands. Show all posts

Sunday, June 21, 2015

Open and close CD / DVD Drive using this trick

0 comments

Open and close (CD / DVD Drive) using this trick

Linux terminal (or Shell language generally) can do many beautiful things such as tricks, whether in terms of benefit of programming, or in terms of tricks and entertainment, and in this lesson we will learn about small code that executes an infinite loop which make the drive (CD / DVD Drive) closes and opens itself repeatedly, and of course will not stop unless you stop your own script, and you will learn about it.

1. First, Create a new text file under any name you want (for example, I I would call it script), at the end of your file name, add .sh 
now the name will be like this : script.sh

Create Document


Script.sh


2. Now, copy the following codes, and paste then in the text file script.sh :

#! / Bin / sh
while [1 = 1]
do
#eject CDROM
eject
#pull CDROM tray back in
eject -t
done

3. Save the file and close it.

4. Go to the File Properties and Permissions tab, check the option appeared in the picture :

allow executing file as program

5. Now run the file, and if this message appears, press Run in Terminal, and now you will see how the drive will still opens and closes on its own, until you stop it.

run in terminal


How do I stop it ? Simply close the terminal window.

     
Read more...

Thursday, February 6, 2014

5 entertaining Linux Commands

0 comments

5 entertaining Linux Commands

Perhaps you need a few quick commands  to apply in Terminal for entertainment after a long day and hard work , for good luck we are here , you will learn about the day to 5 entertaining commands to run in your terminal.

telnet towel.blinkenlights.nl

telnet towel.blinkenlights.nl

It works on most Linux distributions , is simply star war scenario works from the terminal , really fun !

sl

sl

Simple command shows you a moving train in Terminal , you can use the For loop if you want to repeat the process quickly or for the infinite and onwards :)

May not be installed on your distribution , use sudo apt-get install sl to install it on Ubuntu and daughters and sudo yum install sl to install it on Fedora and derivatives.

fortune

If one cannot enjoy reading a book over and over again, there is no use in reading it at all. - Oscar Wilde

Is useful and fun at the same time , showing the words and a group of ruling party and entertaining in English , contains a lot of them , some really entertaining , you'll need to install it in Ubuntu by sudo apt-get install fortune and sudo yum install fortune in Fedora .

yes i love linux

i love linux i love linux i love linux i love linux i love linux
Are you well now? Dish it and you'll find words of love to fill the Linux terminal back and back :)

cmatrix


cmatrix

Certainly you will learn to symbolize what those green numbers and letters .. Matrix .. The causal .. In the end we all enjoyed by the respective movements Mr.Anderson a combat :) 

You'll need to install the package on your distribution cmatrix .. As usual, you can use apt-get and yum.


     
Read more...

Sunday, January 26, 2014

Changing gtk themes via the Command Line

0 comments

Changing gtk themes via the Command Line

This list of commands which we are going to show later helps changing various theme-related settings in Gnome based desktop.

These commands work with Gnome 3, Unity, Cinnamon, Mate desktop, and also the old Gnome 2 desktop(if you still using it).

Why we need to type some commands to get it done instead of a Gui tool ?

This is important to ask in such situation. In Gnome 2(and Mate today) all the these settings can be easily changed using build-in Gui tool called Appearance Preferences. Unfortunately in modern desktops such as Unity Gnome 3 ... we have Gui tools that can do the same, like Gnome Tweak Tool, Ubuntu Tweak, or MyUnity, but with limitations. It means that "Appearance Preferences" (Gui tool to tweak Gnome 2 and Mate) is powerful than any other tweaking tool.

Since "Appearance Preferences" doesn't come with all desktops except Mate, The command line will be the only replacement.


1 - Change GTK Theme


Unity, Gnome 3 Shell/Classic, Cinnamon
gsettings set org.gnome.desktop.interface gtk-theme "Mytheme"

Mate
mateconftool-2 --type=string --set /desktop/mate/interface/gtk_theme "Mytheme"

Gnome 2
gconftool-2 --type=string --set /desktop/gnome/interface/gtk_theme "Mytheme"

2 - Change window theme (Metacity)


Unity, GNOME 3 Classic (Metacity), GNOME 3 Shell (Metacity > Mutter)
gsettings set org.gnome.desktop.wm.preferences theme "Mytheme"

Cinnamon (Metacity > Muffin)
gconftool --type=string --set /desktop/cinnamon/windows/theme "Mytheme"

Gnome 2 (Metacity)
gconftool-2 --type=string --set /apps/metacity/general/theme "Mytheme"

Mate (Metacity > Marco)
mateconftool-2 --type=string --set /apps/marco/general/theme "Mytheme"

3 - Change Shell theme


Gnome Shell (user-theme extension must be enabled)
gsettings set org.gnome.shell.extensions.user-theme name "Mytheme"

Cinnamon
gsettings set org.cinnamon.theme name "Mytheme"

4 - Change GTK color scheme


Unity, GNOME 3 Shell/Classic, Cinnamon
gsettings set org.gnome.desktop.interface gtk-color-scheme "bg_color:#e9efe9;fg_color:#444444;base_color:#ffffff;text_color:#333333;selected_bg_color:#6666cc;selected_fg_color:#eeeeee;tooltip_bg_color:#222222;tooltip_fg_color:#dfcfcf;link_color:#cc0099;"
  • Reset color:
gsettings set org.gnome.desktop.interface gtk-color-scheme ""

Mate
mateconftool-2 --type=string --set /desktop/mate/interface/gtk_color_scheme "bg_color:#e9efe9;fg_color:#444444;base_color:#ffffff;text_color:#333333;selected_bg_color:#6666cc;selected_fg_color:#eeeeee;tooltip_bg_color:#222222;tooltip_fg_color:#dfcfcf;link_color:#cc0099;"

Gnome 2
gconftool-2 --type=string --set /desktop/gnome/interface/gtk_color_scheme "bg_color:#e9efe9;fg_color:#444444;base_color:#ffffff;text_color:#333333;selected_bg_color:#6666cc;selected_fg_color:#eeeeee;tooltip_bg_color:#222222;tooltip_fg_color:#dfcfcf;link_color:#cc0099;"
  • Reset color :
gconftool-2 --type=string --set /desktop/gnome/interface/gtk_color_scheme ""


Note : You can also try to use some other tools like dconf-tool or gconf-editor

     
Read more...

Friday, January 24, 2014

Harmful Linux Commands

0 comments

Harmful Linux Commands

There is always the good and the bad wherever you go.
The same thing with Linux commands, there are good commands and bad commands as well.

When It comes to bad commands, we find that, the most Linux users who have executed them are newbies who was given wrong directions as help.


Note : don't try to run those commands in your real machine, use Virtualbox if you love testing things.

I'm sure there are other commands which can be used against us.

These commands which I'm going to show are mostly found in forums where a lot of newbies are seeking for help and other online websites targeted at Linux users.


mkfs.ext3 /dev/sda
The command above will delete and erase all Data from the hard disk and format it to ext3.

mv ~ /dev/null
Delete and erase all Data from your root directory by moving them to an invalid directory.

rm -fr /
It is well known command and simplest too. It recursively remove all files from the root.

mv /home/* /dev/null
Moves all home directories to unknown location /dev/null, which means, the home directories with all Its content will be erased.

chmod -R 777 /
This will not cause a physical harm, but It will drive to low security by granting read, write and execute rights on every file to every user on that system.



     
Read more...

Wednesday, January 15, 2014

How to change date and time in Linux

0 comments

How to change date and time in Linux

It's easy to change Time and Date in Linux, You can use Gui for that, but some Desktop environments do not have a Gui to change time and date, and Servers have no Gui at all.

So we need a command line for that :D
Remember : It's easier with The command Line :)

1- To change Date and Time :


First we have to use root privileges.

and one command such as this :

To change Date and Time in Linux

Or that one :

To change Date and Time in Linux

Oct stands for October.
2006 = a year.
18:00:00 = 18 hours
                   00 Minutes
                   00 Seconds

To make it short and very easy we can use this command :

To change Date and Time in Linux

%Y stands for the year.
%m stands for the month.
%d stands for the day.

So we will put the year first : 2008.
and month : 11.
and day : 28.

Example : 

We would like to change our date  to 2014, month May, and day 2.

date +%Y%m%d -s 20140502

2 - To change Time only :


Type this command with your modification of the time :

To change Time in Linux

10 : Hours.
13 : Minutes.
13 : Seconds.

Note : # sign is not part of the commands, It indicates only that we are signed to terminal as root.

     
Read more...

Thursday, January 9, 2014

apropos command

0 comments

apropos command

It helps to find commands which their descriptions contain a specified word. Displays the name of the command and the first line of the description.

apropos find
Find commands with descriptions that include the word find.

apropos find | less
Find commands with descriptions that include the word find and use less to display the results so you can scroll up or down through them.

     
Read more...

du command

0 comments

du command

Displays usage in kilobytes for contents of the current directory or for a specified file or directory.

du /root

Shows how much disk space is used by the /root directory.

     
Read more...

Tuesday, December 31, 2013

Find command

0 comments

Linux commands - Find command

Find files under a specified directory that match conditions you specify.

find / -name myfile*

Find files in the root directory and all directories under it that have file names beginning with myfile. The * is a wild-card character that represents any number of characters. The ? is a wild-card character that represents a single character.

find -name '*.pdf' -print -exec chown User2 {} \;

Find all files in this directory and all subdirectories that end with .pdf, display the names of all files that are found on the screen and, for each file (indicated by the curly braces — {}), change its owner to User2.
 The -print option is not necessary, but it is handy to track the progress of the find command. If you do not use -print, the find command is silent except for error messages from find or from chown.

find -name '*.pdf' -exec grep -il 'SOMETHING' {} \;

Find all files in this directory and all subdirectories that end with .pdf and look for the pattern SOMETHING in each of the files. The -i option to grep makes the search case-insensitive. The -l option to grep causes grep to display the names of the files that have SOMETHING in them. When a file is found that contains SOMETHING, this command displays the full path to the file from the current directory (for example,
./home/user/Documents/Linuxcommand.pdf).

     
Read more...

Monday, December 30, 2013

Ls command

0 comments

Linux commands - Ls command

List the files in the current directory.

ls -al
List all (-a) the files in the current directory in long (-l) format.

ls *.pdf
List files in the current directory that end with .pdf. The * is a wild-card character that represents any number of characters. The ? is a wild-card character that represents a single character.

ls /home/user
List the files in the directory /home/user.

     
Read more...

Wednesday, November 20, 2013

Basic Linux commands

0 comments

Basic Linux commands

Almost These Linux commands are basics except those which relate to package manager, we all know that they differs, Ubuntu, Mint ... use Apt, Arch uses Pacman ...

Here are some Basic Linux commands :

Display Linux distributor's ID
lsb_release -is

Display Linux release number
lsb_release -rs

Display Linux code name
lsb_release -cs

Display machine hardware name
uname -m

List all PCI devices, such as display card and ethernet card.
lspci

Reclaim memory which stores pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches

Display a list of modules in the Linux Kernel
lsmod

List USB devices
lsusb -v

Display the status of ethernet card
sudo ethtool eth0

List hardware
sudo lshw

List harddisk partitions
sudo fdisk -l

Display SATA harddisk parameters
sudo hdparm -I /dev/sda

Display disk space usage
df -h

Display file/folder space usage
du -bsh FOLDER_NAME

Display amount of free and used memory
free

Display processes
ps -e

Display a tree of processes
pstree

Display processes dynamically
top

Terminate a process with a given process id
sudo kill -9 PROCESS_ID

Terminate all processes with a given name
sudo killall PROCESS_NAME


List files which are opened by a given process
lsof -p PROCESS_ID
lsof -c PROCESS_NAME

List processes which opened a given file
lsof FILE_NAME

List processes which are using port 80
lsof -i :80

Configure an ADSL connection
sudo pppoeconf

Starts up ADSL connections
sudo pon

Shuts down ADSL connections
sudo poff

Display MAC of a given IP address
arping IP_ADDRESS

Display NetBIOS name of a given IP address
nmblookup -A IP_ADDRESS

Display IP address and MAC
ifconfig -a

Display route
netstat -rn

Set MAC of ethernet interface
sudo ifconfig eth0 hw ether 00:11:22:33:44:55

Display information of a domain name
whois example.com

Display the network path to a given host
tracepath example.com

Request an IP address from DHCP server
sudo dhclient

Temporarily restart an init script
sudo /etc/init.d/SCRIPT_NAME restart
Temporarily stop an init script
sudo /etc/init.d/SCRIPT_NAME stop

Add a user
sudo adduser USER_NANE
Delete a user
sudo deluser USER_NAME

Change user password
sudo passwd USER_NAME

Changes user fullname, office number, office extension, and home phone number information.
sudo chfn USER_NAME

Display user information
finger USER_NAME

Temporarily prevent a user from logging in
sudo usermod -L USER_NAME

Revoke the operation above
sudo usermod -U USER_NAME

Add a user to admin group
sudo usermod -G admin -a USER_NAME

Set the HTTP proxy
export http_proxy=http://PROXY.DOMAIN.NAME:PORT

Modify the information displayed after logging in
sudo vim /etc/motd.tail

Choose the input method for X Window
im-switch -c

Convert the file name from GBK to UTF8
convmv -r -f gbk -t utf8 --notest FILE_NAME

Convert the file content from GBK to UTF8
iconv -f gbk -t utf8 FILE_NAME

Convert tags in '*.mp3' from GBK to UTF8
find . -name '*.mp3' -execdir mid3iconv -e GBK {} \;

Read a long file
less FILE_NAME

Print lines matching a pattern
grep REG_EXP FILE_NAME

Display a list of file name. The files contain a given string.
grep -lr REG_EXP PATHNAME

Display all '.txt' file
find . -name '*.txt'

Create two empty files
touch file_name_1 file_name_2

Create directory. Create parent directories as needed.
mkdir -p /tmp/a/b/c/d/e

Change working directory to the home folder
cd

Change working directory to the previous working directory
cd -

Display hidden files
ls -a

Copy directory. Preserve links, file mode, ownership, timestamps.
cp -a SOURCE_DIRECTORY DEST_DIRECTORY

Determine file type
file FILE_NAME

Output the last 6 lines
tail -n 6 FILE_NAME

Copy files via SSH
scp -rp FILE_NAME USERNAME@HOST:DEST_PATH

Rename '*.rm' files to '*.rmvb' files
rename 's/.rm$/.rmvb/' *

Change the file name to lowercase
rename 'tr/A-Z/a-z/' *


Display subdirectories in current directory
ls -d */.

Display file number in current directory
ls . | wc -w

Extract "*.gz" file
gunzip FILE_NAME.gz

Extract "*.tar.gz" file
tar zxf FILE_NAME.tar.gz

Extract "*.tar.bz2" file
tar jxf FILE_NAME.tar.bz2

Do compression
tar czf FILE_NAME.tar.gz FILE1 FILE2 FILE3
tar cjf FILE_NAME.tar.bz2 FILE1 FILE2 FILE3

Displays a calendar
cal
cal MONTH YEAR

Set the date and time via NTP
sudo ntpdate ntp.ubuntu.com

Poweroff your computer
sudo halt
sudo shutdown -h now

Poweroff your computer in 23:00
sudo shutdown -h 23:00

Poweroff your computer after 60 minutes
sudo shutdown -h +60

Reboot your computer
sudo reboot
sudo shutdown -r now

If you want some program to start up automatically, please put '.desktop' files into '$HOME/.config/autostart'

You can configure "preferred applications" by this file "$HOME/.local/share/applications/mimeapps.list"

Continuously monitor the memory usage
watch -d free

Display HTTP HEAD response
w3m -dump_head http://example.com

Display file content with line number
nl FILE_NAME

Eliminate Rootkit
sudo rkhunter --checkall

Change hostname
sudo hostname new_name

"Tasksel" group software packages into "task"s. You can select a "task" and then install all necessary software packages. It is easy to set up LAMP servers or cloud computing servers.

Show all tasks
tasksel --list

Display the extended description of a task
tasksel --task-desc lamp-server

List the packages which are parts of a task
tasksel --task-packages lamp-server

Install/remove a task
gksudo tasksel

Change Process priority
renice NEW_PRIORITY `pgrep NAME_OF_PROCESS`
example: renice 5  `pgrep firefox`  
         renice -5 `pgrep wine-server`    
               high <------------------> low
NEW_PRIORITY = -19, -18, -17 [...] 18, 19, 20

Clear Bash history
history -c

If you want to use colorful "ls", that is, use colors to distinguish types of files, you can add these lines in $HOME/.bashrc:

if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
fi

$HOME/.thumbnails/ directory is a cache dir GNOME makes when you browse through your folders in nautilus.
It contains thumbnail pictures of picture files you've previously looked at.

You can get its total size by
du -bs $HOME/.thumbnails/

You can delete the files in the .thumbnails directory that haven't been accessed for seven days, to free disk space.
find $HOME/.thumbnails/ -type f -atime +7 -exec rm {} \;

Capture screen after 10 seconds
gnome-screenshot -d 10
Capture current window after 10 seconds
gnome-screenshot -wd 10

Start GConf editor:
Press Alt+F2, type 'gconf-editor'.

Set apt source
sudo software-properties-gtk
sudo software-properties-kde

Display the packages which are not installed but have remained residual config
dpkg -l | awk '/^rc/ {print $2}'

Add a PPA repository:
sudo add-apt-repository ppa:PPA-REPOSITORY-NAME

Display a list of files. The files are installed from a given package.
dpkg -L PACKAGE_NAME

Display a list of packages. The packages installed a given file.
dpkg -S FILE_NAME

Display a list of packages. The name of packages matches given regex pattern.
apt-cache search REG_EXPRESSION

Display a list of packages. The packages provide a given file.
apt-file search FILE_NAME

Display a list of packages. The given package depends on the list of packages.
apt-cache depends PACKAGE_NAME

Display a list of packages. These packages depend on the given package.
apt-cache rdepends PACKAGE_NAME

Prompt for a disk to be inserted and then add the disc to the source list.
sudo apt-cdrom add

Install the newest versions of all packages currently installed on the system.
sudo apt-get upgrade

Delete residual package configuration files.
dpkg -l | grep ^rc | awk '{print $2}' | sudo xargs dpkg -P

Automatically install necessary files for './configure ; make ; make install'
sudo auto-apt run ./configure

Save the list of packages currently installed on your system.
dpkg --get-selections | grep -v deinstall > SOME_FILE
Then use the file to restore packages.
dpkg --set-selections < SOME_FILE ; sudo dselect

After running "sudo apt-get install", "*.deb" files are stored in "/var/cache/apt/archives"
You can clean this directory by:
sudo apt-get clean

Display URL for a given package
apt-get -qq --print-uris install PACKAGE_NAME

Display some statistics about the apt cache
apt-cache stats

Display all package name
apt-cache pkgnames

Display some information of a given package
apt-cache show PACKAGE_NAME

     
Read more...