
Part 1:- SAP Basis OS support on SUSE Linux for beginners
As a SAP Basis consultants you are advised to understand the most commonly used Linux commands that are necessary while supporting SAP customers for day to day work. It is very common that basic commands should be handy with SAP Basis consultants.
Basic commands
Linux administrator can login with tools like putty or kitty or other applications available in market or allowed by customer, with either root or sidadm. Whereas both the IDs have different rights W.R.T OS and sap application.
“ls” will only show the list of files and directories on that particular mount point /directory/path.
Ls - al ( it will list directory/files as well as the hidden files)
Ls -ltr (List all the files in the currently directory in ascending order)
Ls -altr (adding a with it will show hidden files also in ascending order)
Ls -lt (List all the files in the currently directory in descending order)
Ls -alt (adding a with it will show hidden files also in descending order)
Ls –ltr | more
cd dirname ( to jump into other directory)
Cd.. ( One step back of directory )
Cd / ( to come back to root directory)
If you want to move to a directory on same path then you don’t have to use “/”.
But if you want to move to a directory outside of current directory or path then you need to use”/”.(give some practical examples)
info (given you the list of all commands available on OS)
(it gives you details of what all
Options are available for
Particular command)
Cat /etc/hosts ( To display file content)
vi <filename> (this is file editor)
( It will display first 10 lines of the file )
( it will display last
10 lines of the file)
Managing files and directories
In this section of the article we will look at moving files and directories around the file system, copying files and directories and finally creating and deleting files and directories. The first command that we will look at is mkdir which creates directories. The mkdir command takes one argument which is the directory name you would like to create
The mkdir also accepts brace expansion which allows you to create multiple directories with one command
As you can above four directories were created ‘tes1’, ‘tes2’, ‘tes3’ and ‘tes4’. The second command I executed contained an asterisk (*) this character is known as a wild card and means any character
rmdir command – Deletes the specified empty directories and folders in Linux.
rm command – Delete the file including sub-directories.
If you use RMDIR to delete a non empty directory, you will get an error message:-
rmdir: <directory name> :Directory not empty.
The other command that we will look at is rmdir. This command removes directories from the file system. However, when using this command the directory has to be empty otherwise the directory will not be removed. The rmdir command takes one argument which is the name of the directory you would like to remove. The rmdir command also accepts brace expansion which is identical to mkdir.
Lets run some practical commands.
The another command that we will look at is cp. This command is used for copying files from one location to another. The cp command takes a wide variety of qualifiers, however, we will only be supplying two arguments with the cp command.
You will also notice that the original copy is still in its current location.
The another command that we will look at is mv. This command is used for renaming files and moving them from one location to another. The mv command takes a few qualifiers and requires at least to arguments, if you are moving a file from one location to another you have to specify the first argument as the filename and the second argument as the destination directory, if you are renaming a file your first argument should be the filename and the second argument should be its new name.
the file was successfully renamed and the ‘test.txt‘ filename no longer exists because it had been renamed.
As I mention previously the mv command can be used to move files and directories from one location to another.
In this section of the training we will look at finding files using two different methods. The first command that we will examine is find. This command has some very powerful features for finding files such as searching by: file access time, file size, filename, file contents, etc.
The first file that we will try and find is ‘passwd‘, the first command we will use is find.
Qualifier | Description |
/ | This argument is where you specify the path in which you would like to search. |
-iname | This qualifier tells the find command that we are performing a case insensitive search. |
public_html | This directory is used to store HTML content. When the Apache web server has been enabled and has the UserDir option enabled this directory is published on the Internet. |
passwd | This argument is where you specify the file which you would like to search for. |
The second example we will do with the find command is find a file which has the keyword ‘damian’.
Qualifier | Description |
/etc | This argument is where you specify the path which you would like to search. In this example we search the /etc directory. |
-type f | This qualifier specifies that we only want to check regular files. |
| xargs grep -l -i “damian” | This section of the command retrieves the filename via a pipe (|) and passes the filename into the grep utility which search for the keyword ‘damian’ and prints out the filename which contains the keyword. |
The another example that we will look at when using the find command is to find files that have a size greater than 500MB.
find /root -type f -size +500M -printf "The %p file is greater than 500MB\n“
Once you have got the hang of the find command you should have no problems finding your files.
Qualifier | Description |
/root | This argument is where you specify the path which you would like to search. In this example we are searching root’s home directory. |
-type f | This qualifier specifies that we only want to check regular files. |
-size +500M | This section of the command specifies the file size we would like to search for. |
-printf “The %p file is greater than 500MB\n” | This qualifier prints a custom message telling the user we found a file greater than 500MB. |
In this section of the training we will look at how to create hard and soft symbolic links. A symbolic link is a reference to another file similar to Microsoft Windows shortcuts. However, Linux has two types of symbolic links. The first type of symbolic link is ‘soft’ which points to filenames instead of the file’s inodes and the second type of symbolic link is ‘hard’ which actually points to the inodes and not the filename.
You cannot create hard links across multiple devices e.g. If you have created separate partitions for /home and /usr you cannot hard link any files from /usr to /home. However, you can create soft links across multiple devices.
The command that you use to create symbolic links is ‘ln‘. This command with no qualifiers and two arguments will create a hard link. However, if you want to create soft links you need to provide the -s qualifier.
the first argument is the actual filename you would like to point to and the second argument is where you want the symbolic link (shortcut) to be.
The below example creates a soft symbolic link for the ‘cal‘ utility which is stored within the /usr/bin directory.
the ‘cal‘ utility was successfully created and ‘ls -l’ shows that the /root/cal file points to the /usr/bin/cal file.
Creating a hard symbolic link to the ‘cal‘ utility.
the hard link was successfully created and it does not show a pointing arrow when issuing the ‘ls -l‘ command. This is because hard links point directly to inodes and not the filename.
STAT command:
the ‘stat‘ command being executed which allows you to examine a file more thoroughly.
Compressing Files
In this section of the training we will look at how to compress files and directories. The utilities that we will be working with are ‘tar‘ (The GNU version of the tar archiving utility) and ‘gzip‘ (Compress or expand files).
gzip is a compression utility and requires the assistance of tar when compressing directories. The first utility that we will examine is tar. tar is used for archiving multiple files and directories which later can be compressed using gzip.
SYNTAX:-
The first example will involve using ‘tar‘ to archive the user Damian’s home directory. Below shows the command used to archive Damian’s home directory and Table 1 explains what each qualifier supplied with the ‘tar‘ do.
you will notice that you have a newly created archive within your current working directory.
Qualifier | Description |
-c | Creates a new archive. |
-f damian.tar | Use archive file. |
The archive can be viewed using the ‘tar‘ command as shown below.
Tar also allows you to exclude certain files and directories by using the ‘–exclude’ qualifier and you can also append files to a tar archive by using the ‘-A’ qualifier.
Once you know how to archive a directory and view the contents of a ‘tar‘ archive you will also want to know how to extract files from the archive. Below shows the command used to extract all the files and directories stored within a ‘tar’ archive.
Qualifier | Description |
x | Extract files from an archive. |
v | Verbosely list files processed. |
f | Use archive file. |
Now that you have an idea on how to use ‘tar‘ we will look at how to use gzip to compress files. The first file that we will compress is the ‘damian.tar’ which we created earlier. Below shows the command used to compress the ‘damian.tar’ archive.
Qualifier | Description |
-9 | Compress better. |
-1 | Compress faster. |
-d | Decompress the compressed file. |
-v | Verbose mode. |
-r | Operate recursively on directories. |
-l | List compressed file contents. |
You will notice the file now has the extension .gz which is a sign that the compression was successful. The next step is to decompress the compressed file using ‘gzip‘. The process of decompressing the file is simple since you only need to supply the -d qualifier followed by the filename.
Once you have decompressed the ‘damian.tar.gz’ file you will notice that the prefix .gz disappears and you will notice the file has been decompressed.
In this section of the training we will look at how to determine a file type e.g. Binary files, text files, compressed archives and many others. In Linux it is not necessary to give extensions to files, however most people do give extensions just for readability. What would you do if you had a directory full of files and none of the files had extensions? Well it’s simple! There is a utility called ‘file’ which determines the file type for any file.
In this section of the training we will look at the ‘history‘ command. The ‘history‘ command is a very useful command as it allows you to track your previously typed commands. If you type ‘history‘ on its own you can view the majority of the commands you have typed as shown below.
The ‘history‘ command returned a list of commands along with a line number. This line number can be useful if you don’t want to type the command out again you can issue an explanation mark (!) followed by the line number and the command will be executed as shown below:-
The ‘history‘ command can also be a little bit of a pain as some users may accidentally type there root password when trying to use the ‘su‘ command to become the root user and the password gets stored within the history. The ‘history‘ command provides a qualifier (-c) which will clear the all the history thus allowing you to erase an previous commands you typed or any accidental passwords you may have typed. It only saves credentials if you are using “su” not if you are logging normally.
LETS CONNECT OVER PART 2 AND PART 3 OF THIS KNOWLEDGE SHARING TO EXPLORE MORE COMMANDS……
Any suggestions and corrections are most welcome.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
13 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 |