Home | Articles | About | Contact | Forum |
Sunday, December 04, 2016



Lunarpages.com Web Hosting

Mailing List

E-mail:
By Joining the mailing list you will be notified of site updates.


Show Your Support For
This Site By Donating:













Audience: Newbies - System Admins
Last Updated: 5/4/2011 3:58:20 PM
**All times are EST**


Using the Bash Shell

By Erik Rodriguez

This article provides a simple overview of the basic commands executed by a bash shell. This document is aimed towards beginners.



Using the Bash Shell

If you don't know what a shell is, click here. Using a shell for the first time can be difficult; especially to native Windows users. The best way to become comfortable with a shell is by practice. Initially, I hated using a shell. I thought the idea of typing in commands was monotonous. Now I live by the shell! Below you will find several examples of how to navigate through Linux using the bash shell.

Changing Directories

Changing directories is a rather simple process; most people remember it from the days of DOS. Using the cd command, you can navigate through the entire directory tree. Extended commands permit users to skip multiple files directories. Notice the output below:

[weaponx@roswell weaponx]$ ls
overflow.c
[weaponx@roswell weaponx]$ cd /
[weaponx@roswell /]$ ls
bin  boot  dev  etc  export  home  initrd  lib  misc  mnt  opt  proc  root  sbin  tmp  usr  var
[weaponx@roswell /]$


Notice that cd followed by / takes us to the main directory. We can get back to our home directory buy using the cd command followed by the full path.

[weaponx@roswell /]$ ls
bin  boot  dev  etc  export  home  initrd  lib  misc  mnt  opt  proc  root  sbin  tmp  usr  var
[weaponx@roswell /]$ cd /home/weaponx/
[weaponx@roswell weaponx]$ ls
overflow.c
[weaponx@roswell weaponx]$ 




Create, Delete, and Move

Initially, you will want to create, copy paste, and delete files. Upon logging in, your shell will start in the /home directory. Below I am logged in as the user weaponx. You can always check what directory you are currently working in by using the pwd command. Short for Print Working Directory. Do not get this command confused with the passwd, the command for changing your password.

[weaponx@roswell weaponx]$ pwd
/home/weaponx
[weaponx@roswell weaponx]$


Using the ls command, the only file in the home directory is the overflow.c file.

[weaponx@roswell weaponx]$ ls
overflow.c
[weaponx@roswell weaponx]$


Red Hat and other distros of Linux will color code the output to help users distinguish between files, folders, and zip files. This is very handy when you have a directory full of files and other folders. Moving on, let's say that we want to created a .txt file named hello. Using the touch command this is very simple.

[weaponx@roswell weaponx]$ touch hello.txt
[weaponx@roswell weaponx]$ ls
hello.txt  overflow.c
[weaponx@roswell weaponx]$ 


As you can see the file was created. That might even be faster than doing a right-mouse click and selecting new text document. Although the file has been created, it blank. To edit the file, you must use an editor such as vim. Now, let's say we don't want that file anymore and we want to delete it. This can be done using the rm command.

[weaponx@roswell weaponx]$ rm hello.txt
[weaponx@roswell weaponx]$ ls
overflow.c
[weaponx@roswell weaponx]$ 


Easy enough right? However, there is no "un-delete" or "restore" command in Linux. Be careful what you delete! NOTE: NEVER EXECUTE THIS COMMAND, rm -rf / Doing so will delete the entire filesystem without asking any questions! Don't be tricked by advanced users trying to play a trick on you... Now let's re-create the file (for practice) and create another folder named files. After that, we'll move the hello.txt file into the files folder. Use the mkdir to create directories, and the mv command to move files.

[weaponx@roswell weaponx]$ touch hello.txt
[weaponx@roswell weaponx]$ mkdir files
[weaponx@roswell weaponx]$ ls
files  hello.txt  overflow.c
[weaponx@roswell weaponx]$ mv hello.txt files
[weaponx@roswell weaponx]$ ls
files  overflow.c
[weaponx@roswell weaponx]$ cd files
[weaponx@roswell files]$ ls
hello.txt
[weaponx@roswell files]$ 


Let look closely at the usage of the mv command. mv is followed by the file name, then the destination directory. More specifically, like this:
mv filename destination
[weaponx@roswell weaponx]$ mv hello.txt files



Linking Files

There will be times when you will want to create "links" without moving files. This works like creating a shortcut to your desktop. You can do this using the ln command. See the output below:

[weaponx@roswell files]$ ln hello.txt /home/weaponx/
[weaponx@roswell files]$ ls
hello.txt
[weaponx@roswell files]$ cd ..
[weaponx@roswell weaponx]$ ls
files  hello.txt  overflow.c
[weaponx@roswell weaponx]$


Walking through it again, the usage is rather simple. ln is followed by the file name, then the destination. More specifically, like this:

ln filename destination
[weaponx@roswell files]$ ln hello.txt /home/weaponx/


The result is simple, it creates a link to the hello.txt files located in the files directory. However, when using the rm command, only the link will be removed. The original file will still reside in the "files" directory.


TCP vs. UDP
Juniper SRX anti-spam filtering config
Windows Server 2008 Clustering Configuration
Windows 2008 R2 Network Load Balancing (NLB)
Extreme Networks: Downloading new software image
Juniper SRX save config to USB drive
Juniper SRX logout sessions
Extreme Networks Syslog Configuration
Command line drive mapping
Neoscale vs. Decru
Data Security vs. Data Protection
Juniper SRX Cluster Configuration
HOWTO - Create VLAN on Extreme Switch
Using a Non-local Colocation Facility
Linux Server Administration
IT Chop Shops
Flow Viewers: SFLOW, NetFLOW, and JFLOW
Exchange 2007 Back Pressure
IPtables open port for specific IP
Politics in IT Departments
HOWTO - Block Dropbox
Cisco IOS Cheat Sheet
Subnet Cheat Sheet
Design a DMZ Network
How DNS works
Firewall Configuration
Juniper SSG Firewalls
Server Management
Configuring VLANs
Runlevels in Linux
Server Clustering
SONET Networks
The Red Hat Network
Server Colocation
Complicated Linux Servers
Dark Fiber
Data Center Network Design
Firewall Types
Colocation Bandwidth




Copyright © 2002-2016 Skullbox.Net All Rights Reserved.
A division of Orlando Tech Works, LLC
By using this site you agree to its Terms and Conditions.
Contact Erik Rodriguez