Basic Linux Commands

Support for *nix systems, apache, mysql, etc

Moderator: 127.0.0.1

Basic Linux Commands

Postby kostyanj » Wed Apr 02, 2003 3:22 pm

==================================================
Manual

man {command}, Type man ls to read the manual for the ls command.
==================================================
Read

read This is an old trick to keep a telnet session from timing out on you.
==================================================
List

ls {path} It's ok to combine attributes, eg ls -laF gets a long listing of all files with types.

ls {path_1} {path_2} List both {path_1} and {path_2}.

ls -l {path} Long listing, with date, size and permisions.

ls -a {path} Show all files, including important .dot files that don't otherwise show.

ls -F {path} Show type of each file. "/" = directory, "*" = executable.

ls -R {path} Recursive listing, with all subdirs.

ls {path} > {filename} Redirect directory to a file.

ls {path} | more Show listing one screen at a time.
==================================================
Change directory

cd {dirname} There must be a space between.

cd ~ Go back to home directory, useful if you're lost.

cd .. Go back one directory.
==================================================
Make directory

mkdir {dirname} To make a new directory
==================================================
Remove directory

rmdir {dirname} Only works if {dirname} is empty.

rm -r {dirname} Remove all files and subdirs. Careful!
rm -rf {dirname} Remove all file and subdir with force.
==================================================
Print working directory to screen

pwd Show where you are as full path.
==================================================
Copy

cp {file1} {file2}

cp -r {dir1} {dir2} Recursive, copy directory and all subdirs.

cat {newfile} >> {oldfile} Append newfile to end of oldfile.
==================================================
Move

mv {oldfile} {newfile} Moving a file and renaming it are the same thing.
==================================================
Remove

rm {filespec} ? and * wildcards work like DOS should. "?" is any character; "*" is any string of

characters.

==================================================
Date

date Shows sys date and time.
==================================================
Apps for basic configuration

Changes services installed or changes them:
Ntsysv or linuxconf
==================================================
Check dir sizes of homes (or any dir) use the following:

Cd /home
Du –s * | sort –rn |head –30

30 is the number of directories starting from the largest.
===================================================
Backup the dir's on a server run the following from /:

Tar -cfz /dir/filename.tgz /var/qmail/ /etc

Verify file is in /home and correct size/date.
Tar and Gunzip
Tar switches /source/ destination

1. Compress. Tar –cvzf filename.tar.gz /sourceoftar
Tar – cvzf etc.tar.gz /etc

2. Decompress

gunzip filename.tar.gz
gunzip etc.tar.gz
or
tar –xf etc.tar
=====================================================
RPM's (Redhat Package Manager)

To install a package: rpm –ivh
ex. rpm -ivh somepackage.1.1-4.i386.rpm

To upgrade a package: rpm -Uvh [filename]
ex. rpm -Uvh somepackage.1.1-5.i386.rpm

To remove a package: rpm -e [packagename only no .rpm or version number]
ex. rpm -evh somepackage
=====================================================

To see if a package is installed: rpm -q [packagename]
ex. rpm -q somepackage
Rpm –q webadmin
=====================================================

To get info on an installed package: rpm -qi [packagename]
ex. rpm -qi somepackage
=====================================================
Disk free space

df amount of free disk space df –I by drives
=====================================================
Disk usage

du amount of used disk space du –s or du -s*
=====================================================
Date

Date shows/sets current date date MMDDhhmmYYYY (sets date/time)
=====================================================
Who is online

Who users currently on system
=====================================================
Free

Free how much RAM and cache is free
=====================================================
Who is online

w users online and what files are being used
=====================================================
Touch

Touch create a empty file
=====================================================
Emacs-nox text editor

Cntrl/x cntrl/s saves document
Cntrl/x cntrl/c closes document
Cntrl/k cut a individual text line
Cntrl/y paste the previously cut test line
Su - Login as root w/root profile via telnet or ssh i.e. paths for root is not the same as

user
=====================================================
VI text editor

I or esc =insert
:=preface all commands
:w= save (:w!)
:u= undo
:q= quit
:d= delete line
:p= pastes at cursor
= pastes after cursor
:yy= copies line where cursor is
:dd = deletes line at cursor
=====================================================
Change access permissions

chmod determines file rights, Chmod 0777 file.txt all can r/w/x, chmod 0755 file.txt public or

grp can only r/x, chmod 0644 test.txt public or grp can only read,
chmd 0711 file.txt public or grp can only x

Another to look at it is:
chmod 600 {filespec} You can read and write; the world can't. Good for files.

chmod 700 {filespec} You can read, write, and execute; the world can't. Good for scripts.

chmod 644 {filespec} You can read and write; the world can only read. Good for web pages.

chmod 755 {filespec} You can read, write, and execute; the world can read and execute. Good for

programs you want to share, and your public_html directory.


=====================================================
To locate file

find –name filename –print
=====================================================
Grep searches a file(s) for matching pattern such as text search.

grep 'text string' -r /home | awk '{print$2}' This goes to the monitor.

grep 'text string' -r /home > textstring.txt For redirect to file.

-r is recursive/home/usrname is starting point
=====================================================
Add a user

Adduser username
=====================================================
Change a password

passwd to set or change password
=====================================================
Delete a user

Userdel username
=====================================================
Modifiy user name

usermod to change username, Usermod -l newname oldname
=====================================================
Enable floppy disk or CD access

mount –t vfat /dev/fd0 /mnt/dos or floppy (for DOS file system) or mount /dev/fd0 (working dir

is /mnt/floppy) or mount –t iso9660 /dev/cdrom /mnt/cdrom
=====================================================
Remove floppy disk or CD access

umount /dev/fd0 or /mnt/floppy
=====================================================
Process identification number and name

ps or ps –ax for all services running or ps –ef > file.txt
=====================================================
Stop Process idendification number and name

kill ps#, kill 188 or kill Kill 188, or kill -9 188
=====================================================
Start or Restart a process

ServiceName , then enter i.e. sshd or httpd etc...
=====================================================
Startup dir(s)

rc3.d is the normal multi user startup (non gui) bootup file in RH.
rc5.d is the normal GUI bootup file in RH.

To stop a service at bootup, you can remove the start (eg S55sshd) instruction from there and that would stop the service starting.
=====================================================
Last

last monitors logins
=====================================================
Last bad logins

lastb monitors bad logins
=====================================================
Make a bootable disk


Bootable disk, Mkbootdisk –device /dev/.fd0 2.0.34-1 (kernal version)
=====================================================
Uname

uname –r is to determine kernal ver
=====================================================
Top

top –c To see cpu usage overall and by sevices
=====================================================
clear cmd line history

rm /home/joe/.bash_history (from home dir of user)
rm /.hash_history (this is for the root user)
=====================================================
ifconfig for status of active interfaces.

ifconfig To get the currently active interfaces.

ifconfig -a Displays the status of all interfaces, even those that are down.
=====================================================
Apache httpd.conf syntax checker (typo's)

apachectl configtest
==========================%D=====
Touch

Touch create a empty file
=====================================================
Emacs-nox text editor

Cntrl/x cntrl/s saves document
Cntrl/x cntrl/c closes document
Cntrl/k cut a individual text line
Cntrl/y paste the previously cut test line
Su - Login as root w/root profile via telnet or ssh i.e. paths for root is not the same as

user
=====================================================
VI text editor

I or esc =insert
:=preface all commands
:w= save (:w!)
:u= undo
:q= quit
:d= delete line
:p= pastes at cursor
= pastes after cursor
:yy= copies line where cursor is
:dd = deletes line at cursor
=====================================================
Change access permissions

chmod determines file rights, Chmod 0777 file.txt all can r/w/x, chmod 0755 file.txt public or

grp can only r/x, chmod 0644 test.txt public or grp can only read,
chmd 0711 file.txt public or grp can only x

Another to look at it is:
chmod 600 {filespec} You can read and write; the world can't. Good for files.

chmod 700 {filespec} You can read, write, and execute; the world can't. Good for scripts.

chmod 644 {filespec} You can read and write; the world can only read. Good for web pages.

chmod 755 {filespec} You can read, write, and execute; the world can read and execute. Good for

programs you want to share, and your public_html directory.


=====================================================
To locate file

find –name filename –print
=====================================================
Grep searches a file(s) for matching pattern such as text search.

grep 'text string' -r /home | awk '{print$2}' This goes to the monitor.

grep 'text string' -r /home > textstring.txt For redirect to file.

-r is recursive/home/usrname is starting point
=====================================================
Add a user

Adduser username
=====================================================
Change a password

passwd to set or change password
=====================================================
Delete a user

Userdel username
=====================================================
Modifiy user name

usermod to change username, Usermod -l newname oldname
=====================================================
Enable floppy disk or CD access

mount –t vfat /dev/fd0 /mnt/dos or floppy (for DOS file system) or mount /dev/fd0 (working dir

is /mnt/floppy) or mount –t iso9660 /dev/cdrom /mnt/cdrom
=====================================================
Remove floppy disk or CD access

umount /dev/fd0 or /mnt/floppy
=====================================================
Process identification number and name

ps or ps –ax for all services running or ps –ef > file.txt
=====================================================
Stop Process idendification number and name

kill ps#, kill 188 or kill Kill 188, or kill -9 188
=====================================================
Start or Restart a process

ServiceName , then enter i.e. sshd or httpd etc...
=====================================================
Startup dir(s)

rc3.d is the normal multi user startup (non gui) bootup file in RH.
rc5.d is the normal GUI bootup file in RH.

To stop a service at bootup, you can remove the start (eg S55sshd) instruction from there and that would stop the service starting.
=====================================================
Last

last monitors logins
=====================================================
Last bad logins

lastb monitors bad logins
=====================================================
Make a bootable disk


Bootable disk, Mkbootdisk –device /dev/.fd0 2.0.34-1 (kernal version)
=====================================================
Uname

uname –r is to determine kernal ver
=====================================================
Top

top –c To see cpu usage overall and by sevices
=====================================================
clear cmd line history

rm /home/joe/.bash_history (from home dir of user)
rm /.hash_history (this is for the root user)
=====================================================
ifconfig for status of active interfaces.

ifconfig To get the currently active interfaces.

ifconfig -a Displays the status of all interfaces, even those that are down.
=====================================================
Apache httpd.conf syntax checker (typo's)

apachectl configtest
=====================================================
Directory Structure basics

/ The 'root' directory; reference point for all directories.

/bin Binaries which are absolutely essential to run Linux.

/boot All the files required for booting Linux on a system.

/dev All the devices have their corresponding files here.

/etc All the configuration files for the various software are stored here. Don't play with this directory.

/home All users will have their 'My Documents' under this directory. If your id is tomh, your 'My Documents' (called home-directory) /home/tomh.

/lib The libraries required by system-applications. (Just like DLLs in Windows.)

/lost+found When a disk-check finds files which are damaged or which are not linked to any directory, they are recovered to this directory. Such damages are almost always due to incorrect shutdown.

/misc Miscellaneous files!

/mnt The directory where peripherals and other file-systems are mounted.

/opt The directory where optional software are installed.

/proc proc houses a pseudo-filesystem. Its contents really do not exist anywhere on the disk, and are made available only when you cd to this directory and look at some file. Don't worry about it, anyway.

/root The home-directory for the super-user: root.

/sbin The system-administration binaries exist here.

/tmp The directory where temporary files are created and stored.

/usr Everything related to users!
/usr/bin /bin houses critical binaries, whereas /usr/bin stores other binaries: not so critical but required nevertheless.
/usr/include The header-files required by programs for compilation.
/usr/lib The libraries required by user-applications.
/usr/local Files peculiar to this particular machine.
/usr/sbin User-administration binaries.
/usr/share Information that can be shared by most users.
/usr/src The source-code for the Linux kernel.
/usr/X11R6 Files needed by the X Window system.

/var Files whose contents vary frequently are in this directory.
/var/log The log-files of the system.
/var/spool Directories for mail, news, printing and other queued work.

Written by FLW from www.elitelinux.com
Last edited by kostyanj on Mon Apr 14, 2003 3:26 pm, edited 3 times in total.
User avatar
kostyanj
Admin
Admin
 
Posts: 836
Joined: Thu Feb 27, 2003 4:08 am

Postby Firest0rm » Tue Apr 08, 2003 8:02 pm

Should you really be showing rm -rf ?? :twisted:
User avatar
Firest0rm
n00b
n00b
 
Posts: 13
Joined: Tue Apr 08, 2003 6:18 pm
Location: Ulster, UK

Postby kostyanj » Tue Apr 08, 2003 10:40 pm

Firest0rm wrote:Should you really be showing rm -rf ?? :twisted:


It is a Linux command and people should know what it does, in case they want to clean out someone else's system. :lol:
User avatar
kostyanj
Admin
Admin
 
Posts: 836
Joined: Thu Feb 27, 2003 4:08 am

Postby wacky-sung » Wed Apr 09, 2003 6:18 am

Thank for taking the effort for showing me all those commands in short.I really new to Linux and still lot more to learn from you guys.By the way,what is rm -rf ?Can you explain that to me?
wacky-sung
End-Loser
End-Loser
 
Posts: 68
Joined: Mon Apr 07, 2003 4:30 am

Postby kostyanj » Wed Apr 09, 2003 8:08 am

rm -rf = remove -recursive -force, so remove files and subdirectories w/o asking yes/no
User avatar
kostyanj
Admin
Admin
 
Posts: 836
Joined: Thu Feb 27, 2003 4:08 am

Re: Basic Linux Commands

Postby January » Wed Jul 09, 2008 8:58 pm

Thank you for posting the basic Linux commands, it would be a very big help for me because I have recently switch my OS to Linux.
Keep posting helpful informations. :)
January
n00b
n00b
 
Posts: 3
Joined: Wed Jul 09, 2008 8:44 pm

Re: Basic Linux Commands

Postby Christine » Sat Jul 19, 2008 11:53 pm

Thank you for the effort of posting that information. I really need to know basics of Linux because I just switch my OS to Linux now.
Christine
n00b
n00b
 
Posts: 3
Joined: Sat Jul 19, 2008 1:51 am

Re: Basic Linux Commands

Postby Chalmer » Mon Jul 21, 2008 7:52 am

Top 10 Ways to Protect Your Linux System

Number 10.

Visit a local computer software store, drift through the aisles filled with internet security and spyware protection products and simply walk on past them. You don't need to spend $49 to protect a home Linux system. Even if you are seriously concerned, there are plenty of Free Open Source solutions available to you that I list later.

Number 9.

Get online and download or order a large set of Knoppix Live Boot CDs and share them freely with your Windows using friends.

This is especially important if you know of a Windows user who recently purchased a DSL or Cable Modem connection and asks you earnestly, "what's spyware?" Save them, for the love of humankind! Get them using Linux before their system is infested with a dozen spywares consuming their bandwidth and system resources. In fact, these handy "live-cd" releases are good for many things including Emergency Booting a Windows PC! One of my friends foolishly ignored this advice and within 60 seconds of connecting his WindowsXP system on my DSL line had a slew of spyware rooted on his hard drive. Ironically, I had been using the same DSL for six months with a basic SuSe 9.3 release and zero issues crept up. Yes, he took a Knoppix CD home with him that night!

Number 8.

Get familiar with the world of OpenSource on sites like Freshmeat.net and see just how much is available to you regarding every aspect of Open Source software. I'm not just talking about security utilities. I'm also referring to the exceptional power of programs like: Firefox web browser, OpenOffice.org 2.0, Apache projects, and MySQL 5.0, among over 105,000 others.


I've been considering printing the full list out in 4 point font and carrying it in my notebook case for that not uncommon moment when someone asks me "is there much software available?" I can just whip out the 100,000+ listing and hand it to them.

Number 7.

Take the time to download and install a patch if a critical update is announced. How frequently do such advisories occur? For the most part only a few times a year at most (obviously, this depends on your applications as much as your Linux flavor/kernel). The important thing is to realize that home Linux use does not require you to patch every time an announcement is made. Just keep your ears out for critical security related patches, if they come.

In the Windows world there is a tendency towards hyper patching. As a result, some of my technically savvy Windows friends switch over to Linux and start patching their systems on an almost daily routine. Then they come to me, panting and sweaty saying, "Oh man, so many patches!" Ironically, even as Microsoft pointed the blame at RedHat for releasing far more patches, they failed to also point out almost none of the RedHat patches were critical security updates. Patch when critical updates come, otherwise relax and enjoy your stable, quality home Linux PC.

Number 6.

Never run executable programs as root. If you login as root and find odd programs you don't recognize, please take the time to move them to a user space. Never run such programs using the ultra powerful root... unless you're particularly bored one day or partial to self-flagellation that is.

Number 5.

This takes me to the next point (about Linux not flagellation). There are multitudes of websites out there offering "free" software and downloads. Please avoid Trojans and other problems by downloading your software from reliable sites. Most websites will provide MD5 checksums and verified downloads protecting you from issues. Stick to known and reliable websites. Hey, not all the points are funny okay!

Number 4.

Lots of people forget that even though your Linux system may be far less vulnerable to viruses and malware, your Windows systems on the same home network remain vulnerable. One major vulnerability of Windows systems on a Linux network is that the Linux machine inadvertently passes along viruses or malware that did not affect it. You can cover this weakpoint by downloading and using Linux based antivirus software. Although it is unlikely your AV software will protect your Linux box from anything malicious, it is highly likely it will keep things away from your Windows systems. Ironic but quite true. You can download a few AV Linux software from:here, or here, or here. You can also find several commercial anti-virus, anti-spam, and anti-malware options.

Number 3.

Yep, this goes in line with tip number 6. Please do not do your internet surfing or day-to-day work on your Linux system as root. Take a brief moment in time and create a secondary login. If you ever need to get superuser powers just use the su command instead of habitually using root, which opens a potentially large hole for fouling up your nice and stable Linux system.

Number 2.

You should enable and use your Linux firewall. The good part is that your Linux flavor is entirely likely to come with a preconfigured firewall that is sufficient. Please be sure this is enabled when you surf the internet. Most Linux flavors come with a very robust and capable firewall preinstalled, but configuring this may be simplified with some of the graphical firewall interfaces including: Firestarter and Guarddog. The key point about your firewall is that you should enable and use it!

Number 1.

Finally, the number one tip for protecting your system from worms, viruses, spyware and malware is to use Linux. You end up avoiding a good volume of issues regarding security and often enjoy better home PC performance to boot!




cabins in quebec anti spyware software
Chalmer
n00b
n00b
 
Posts: 3
Joined: Mon Jul 21, 2008 7:45 am

Re: Basic Linux Commands

Postby danny0085 » Thu Aug 25, 2011 9:35 am

Here you can check out the most used linux commands

http://commands.tips-linux.net
danny0085
n00b
n00b
 
Posts: 1
Joined: Thu Aug 25, 2011 9:33 am


Return to Unix/Linux

Who is online

Users browsing this forum: No registered users and 2 guests

cron