Working with Linux command line


Hi, I am Malathi Boggavarapu working at Volvo Group and i live in Gothenburg, Sweden. I have been working on Java since several years and had vast experience and knowledge across various technologies.

This post explain different commands used in Linux environment. I use Cygwin to interact with Linux server remotly and access and process different files over there.
Let's get started.

ssh [remote_server_ip_address] - Connect to the remote server.

scp -r  xxx.pl  user@127.0.0.0:/tmp - Connects to the remote server with specified IP address with user and copy the file xxx.pl to the folder tmp on remote server.

scp -vp user@127.0.0.0:/var/logs/audit\* /cygdrive/c/logs/auditlogs - Connects to the remote linux server with specified IP address as user and copy all the files from the folder /var/logs/audit to the destination windows folder c/logs/auditlogs. As i was working with Cygwin to connect to remote linux server, the destination folder should be preceded with cygdrive.

cp [audit.log.]* /tmp - To copy files that starts with a pattern audit.log. to the destination folder /tmp in the linux server.
Ex: audit.log.2018-09-01, audit.log.2016-09-02, audit.log.2017-09-02 and so forth.

cp audit.log.2018-09-15* /tmp - To copy all the files that with pattern audit.log.2018-09-15

rm -r auditlogs/* - Remove all the files in auditlogs directory.

chmod -R 777 /tmp/auditlogs - To give permissions RWX for all the files in auditlogs directory.

ls /tmp/auditlogs - List all the files from the directory auditlogs.

ls - List the files from the current directory

ls -la - List all the files from the current directory with the metadata information.

Ex: The interesting columns below are first and fourth. If you want to know the file size refer to the fourth column and first column represents access permissions

drwxrwx---+ 1   user1   Domain Users     0       Aug 30 10:42    .
drwxrwx---+ 1   user1   Domain Users     0       Sep 20 16:43     ..
-rwxrwx---+ 1    user1   Domain Users   6394   Sep 12 09:35    jbossctl.sh

less /etc/httpd/conf/httpd.conf - It loads only the less content in the file instead of loading all the content of the file which would be large.

cp test.html test1.html - Creates a file test1.html if it does not exists and copy the contents of test.html into it.

cp ~/east-library.html east/index.html - If your current working directory is different and if you want to copy any file located at home directory, ~/ allows you to do that. Here it copies the file east-library.html from the home directory of linux to the east directory.

mkdir east west - Create two directories east and west with this command.
mkdir east/images west/images - It allows you to create images folder inside the east and west directories.

How to ignore comments and fetch only the actual content from a file using grep

grep -v '^#' /etc/httpd/conf/httpd.conf | less

The above grep command operates on httpd.conf file and prints out only the content ignoring the comments in the file which start with #.

-v option reverses the meaning of regex.
^ represents the begining of the line

As comments always start in the beginning of the line in httpd.conf file, ^# is used as regex to locate the comments  and finally the output is piped to less command to see only less content of the file instead of seeing the whole file which would be large.

How to search content in the opened file

After opening a file using vim or nano and if you want to search for content or text inside the file, press / and type the text to find it out.
Example: /sometext

Cygwin commands

cygcheck -c - Shows all the packages that were installed in Cygwin

-- More to come

Comments

Popular posts from this blog

Bash - Execute Pl/Sql script from Shell script

How to get client Ip Address using Java HttpServletRequest

How to install Portable JDK in Windows without Admin rights