Tag: pwd

gnuBy Rand Whitehall

In the Linux command line shell, moving around from directory to directory, adding new directories, and deleting old directories is easy once you know the proper commands. Again, with Linux, you are limited only by your brain! If you know all the commands, then you weild great power. But if you know only a few commands, it’s like you are standing in the airport in Tokyo and want to know where the bathroom is, but only know how to say hi and bye in Japanese.

Let’s get to it. Open a shell (or terminal) and type each line below followed by enter:

cd

pwd

You should be in your home directory, which is the same name as your username. So if your username is barney22, your home directory should be /home/barney22.

Now, let’s create a new directory to play with. (Remember, when learning the command line in Linux, always play with new directories and files you create to practice with. Never practice with important files and directories.) Type this:

mkdir doggy [enter]

ls [enter]

Now you should see your new directory called doggy in the ls output. Great! Now what? Let’s change the name. Type:

mv doggy doggyDo [enter]

ls [enter]

And you should see the directory name has been changed from doggy to doggyDo. Great! Hmmm… Now let’s go into the doggyDo directory and create a text file.

cd doggyDo [enter]

touch shibaken.txt [enter]

ls [enter]

Now, you should be in your doggyDo directory and see the new text file you created with the touch command. If for some reason you got lost somewhere along the line, go “home” by typing this:

cd [enter]

A cd command with no destination will take you home every time.

Now, let’s say you want to move the doggyDo directory into another directory. Let’s create another directory first, like this:

cd [enter]

mkdir doggyDocs [enter]

Now let’s move the doggyDo directory into the doggyDocs directory like this:

mv doggyDo doggyDocs [enter]

ls [enter]

You should see the doggyDocs directory now, but not the doggyDo directory because it is inside doggyDocs.

cd doggyDocs [enter]

ls [enter]

You should see your doggyDo directory there inside doggyDocs.

I hope you learned a lot about creating and moving directories around in the Linux command line. If this was a bit confusing, then just go through it again slowly. With a little practice your fingers will know what to do as soon as you think of it!

Rand writes about web design, Linux, men’s health and more. Please check out his DE safety razor site for shaving info and tips and the latest on the Merkur Futur safety razor. It’s a great resource for those who are passionate about a quality, close shave.

Tags: , , , , , ,

Important Unix Commands That You Should Know

By Bernard Peh

Unix is one of the most important operating system today. Its powerful features, scalability, strong security, and support for multiple users have made it the top choice operating systems for server, workstations and mainframes.

It is good to have some knowledge of Unix commands especially if your web host is Unix/Linux based. You could do alot of things by yourself by logging into the server via Secure Shell(SSH). This article will describe some of the important “need to know” Unix commands.

1. ls

This command will show you what files are in your current directory. If you add in a -F option, ie “ls -F xxx”, there will be a “/” appended to the end of directory names, * to executables and @ to links. “ls -a xxx” will display all hidden files as well. This is also the most used command.

2. cd

Change directory. If you type “cd xx”, it means to change to the specified directory “xx”. “cd ~” means to change to your default home directory.

3. cp “a b”

Copy file a to b. If b is a directory, the new file will be named b/a.

4. mv “a b”

Move files from a to b. For example, if I type “mv songs.txt /tmp”, the file songs.txt will be moved to /tmp/songs.txt. Moving a file is the same as renaming a file.

5. echo “text”

Print “text” to the terminal. If “text” is surrounded by double quotes, the text will be printed with any environment variables such as $HOME. If “text” is surrounded by single quotes, the “text” is printed without any special processing.

6. pwd

Print the current working directory. Useful command when you are lost in the directories.

7. cat “file”

Print the contents of the specified file(s) to the terminal.

8. less “file”

Display the specified file one screen at a time. Press the spacebar to go to the next screen. Press Q to quit. You often combine “less” with some other commands such as “cat abc | less”. This command means you print the contents of the file abc and display it one page at a time.

9. ps

Display information about your running programs. This is a good command to use if your server is slow and you suspect that some applications are taking too much memory. The most famous command using ps is “ps aux”. This will display useful information on the running programs.

10. rm

Remove or delete a file. If you type “rm -r directory”, it will remove a directory and all the files underneath it recursively.

11. man

This is the most important command. man means “manual”. If you are stuck with cat command for example, type “man cat” and you can see the help file.

Bernard Peh is a great passioner of web technologies and one of the co-founders of SiteCritic Website Reviews. He works with experienced web designers and developers for more than 5 years, developing and designing commercial and non-commercial websites. During his free time, he does website reviews,freelance SEO and PHP work.

Tags: , , , , , , , , , , ,

An Introduction to Linux Shell Commands

By Erick M Aqqa

The Linux system often intimidates beginners, what with the need to type in a command or two every now and then. However, Linux commands (or shell commands, to put it more accurately) follow a rather logical and sensible pattern and all you need to do is get used to it! Most shell commands are roughly 3, or at most 4 letters long. The more frequently needed commands are shortened further usually.

The man command is a reference to ‘manual’, i.e. the documentation that comes preloaded in Linux systems to help you with common problems faced by a user. These man(ual) pages are certainly not meant to be standalone guides for beginners, but instead, they need to be used as reference material to corroborate what you’ve learnt/tried elsewhere.

The info command is another way to look up reference material for GNU information and troubleshooting suggestions. It isn’t completely the same as the man pages, as there is a scope for using ‘hyperlinks’, to make it easier to browse through the material you need. There are shortcuts for scrolling through pages too.

The date command is self-explanatory. It will tell you about the current time and date on the system. On those lines, the cal command will display a neat calendar of the current month (or that of any particular one you choose).

The ls command is meant to help you list the contents of the directory you choose. This means that you will get to see all the files and directories inside your current directory.This command also has switches to modify its behavior and functionality. For example, adding -l after ls will give you a more detailed description of the contents of the directory you’re in. you’ll get to see details about file permissions, modification dates, groups, sizes and owners. The -a switch helps you see all the files in your current directory, including the hidden ones. (Hidden files in Linux have their filenames starting with a ‘.’ i.e. a period)

In case you lose track of the current directory you are in, type pwd, which prints the current directory you are working in. Once you’ve got to know that, you can navigate around the Linux file system using the cd command, where ‘cd’ stands for ‘change directory’. This can work on both relative and absolute terms, i.e., you can work by specifying the entire directory, starting from ‘/’ (the home directory) to the directory/file you want to go to. Otherwise, you can also use the ‘.’ or ‘..’ system. The latter tells the compiler that you want to go to the parent directory of your current one, making it an easy alternative to typing the entire path every time.

When you start working with simple files, like text files, the cat command will come in handy. It ‘concatenates’ the content of one or more text files, letting you see all of the text they contain.

The ps command lists all the processes currently running on your system in your current terminal.

The shell commands in this article are a good way to start off in the Linux environment. They are simple enough for you to get an idea of how the entire system works, and will probably help you to try out more advanced steps later!

To know more about Linux shell commands, click here

Linux2Aix is an upbeat Linux blog containing all the latest and the newest Linus news and how-to’s for both amateur and professional Linux lovers

Tags: , , , , , , ,

The Complete Steps to Create and Run a Linux Script to Run Linux Commands
By Clyde E. Boom

Creating and running a Linux script to automatically run a series of Linux commands that you commonly run is easy!

With a Linux script, you put a series of routinely run commands in a text file, and then run all of them by simply typing in the name of the file and pressing Enter.

Linux Script Example to Create a Script to Automatically Run A Series of Linux System Administration Commands2455513753_282aa586b7

Follow along with the steps in the example below to create and run your first Linux script!

1. Run a Linux text editor.

2. Put the following text at the top left of the text file (indented below for emphasis):

#!/bin/bash

This indicates that the text file is a Linux script file.

Press Enter twice to have a blank line below the line above.

3. Put the Linux command(s) in the script file.

The Linux commands below are used to provide an example. You can put any commands in a script.

The Linux commands below will: clear the screen, change into the /etc directory path, and then show the current path with the Linux pwd (path to working directory) command.

Then provide a long list of the fstab file (to show you that it’s there) and then change into your home directory (represented by the ~ symbol) and then show the path of the current directory.

The Linux echo command is not required, but has been put in the file to show the progress of the execution of the script.

Also, you don’t need to indent the commands below in the Linux script – they are just indented here for emphasis.

clear
echo The screen has been cleared

cd /etc

pwd

echo This is the etc directory

ls -l fstab

echo This is a long listing of the fstab file

cd ~

pwd echo Now in my home directory

Linux Commands Training Tips: A Linux script can contain hundreds of lines of text if necessary – and also include complex programming logic, such as if . . . then statements.

4. Save the text / script file with a meaningful name to create it and by give it a name.

For example, if you want to list files in a few directories, call the file: listdirs

5. Run the Linux chmod command to change the permissions of the file and make the Linux text file “executable”.

In our example, the file is named: listdirs

Below is a Linux chmod command example for running the chmod command to change the permissions of the Linux script file – and to make the listdirs text / script file “executable”, so that you can run the script file in the same way as you run a command.

The $ (dollar sign) below is the Linux command line prompt. Don’t type in the $ (dolar sign), type in the command that appears at the right of the $ prompt.

$ chmod u+x listdirs

The Linux command above is chmod and it is being used to assign the x (executable) permission to the u (user) of the file with: u+x and the script file name is listdirs.

Running a Linux Script to Run System Administration Commands

To run a Linux script (that is in the “current” directory), such as the listdirs script, simply type in a period (dot) and a space and then the name of the file and press Enter.

$ . listdirs

The concepts and Linux command examples shown above work in Red Hat, Ubuntu, Fedora, Slackware, and Debian Linux – and also ALL Linux distributions.

By the way…do you want to learn exactly how to use Linux and run Linux commands for Linux System Administration and get real, practical Linux training experience by running hundreds of examples of Linux commands?

Just click to download my free new Linux commands training course book and Linux audio podcast (.mp3) files here: Linux Commands Training Mini-Course

Clyde Boom says “Learn how to use Linux commands with easy, self-paced Linux training materials that show you how to run hundreds of examples of the essential Linux System Administration commands – and get that new and better job, promotion, raise – or keep your current job!”

You can get your instant access to my free Linux commands training course at:
http://www.LinuxCommandsTrainingCourse.com

Tags: , , , , , , , ,
Back to top