Skip to main content

Posts

Showing posts with the label linux commands

Control Linux Box using Terminal

You can shutdown, restart a linux box from Terminal. You can use the following commands to do so Open Terminal Type in “ sudo restart ” to restart the system Sometimes you may get the error “command restart not found” if you get this error then try the commands using sudo /sbin/restart or sudo /sbin/shutdown –r now   Get more help on shutdown command using man shutdown

wget error–“zsh: parse error near &”

There is no doubt that I prefer wget way over any other type of downloads… Syntax: wget <DOWNLOAD_URL>   If you get this error “ zsh: parse error near & ” then its probably because your download URL has a “&” so you should try giving your DOWNLOAD_URL in double quotes wget “<DOWNLOAD_URL>”   If you are trying to download from a site which needs you to give your credentials then you can try giving it this way wget --http-user=<UserName> --http-password=<Password> “<DOWNLOAD_URL>”   Hope this helps

Shell Script to Check if Selenium Server is Running!

Many a times we would want to write up a script to start the selenium server using a shell script… So here is the script     #!/bin/sh # # @Author – Sirisha # @Date   - May 29 2012 # Script to start the Selenium Server on a given host #   # Defined the hostname hostname=somehostname # Defined the path to the selenium server serverPath=~/seleniumServer/ # Define the Selenium Server version jar server=selenium-server-standalone-2.12.0.jar # Define the Search String for the server SERVICE_STRING="'java -jar $server'"   # Clear the terminal clear   echo "service string is: $SERVICE_STRING" echo "Starting Selenium Server on $hostname"   # Run the command to get the process list ps -ef | grep -v grep | grep selenium   # Check if the Selenium Server is already running if [ $? -eq 0 ] then     echo "$server is running, everything is fine" else     echo "$server is not running"  ...

How does Shell find out which command/script I am trying to execute?

This is nothing new but yet I thought why not document it so that its etched into my memory (Ya I know I am selfish ) When you run a command or try executing a shell script, the shell first tries to look if your script is found in the Current Directory. To execute a shell script you should be in the same directory where it was created/written. Now this isn’t possible always – so what to do? There are two ways:   Method 1 - When you are executing the script, give the full path to the script! Now if you go by the usual file/folder structure in most of the software engineers – you can go crazy with the paths – the depth at which the script is found can drive you insane   So thankfully we have another way   Method 2 - Add the folder of your script to the PATH variable. What I suggest is create a folder for all your scripts – say myScripts and then add this to your PATH variable. If you are new to using the PATH variable, I suggest you go through this link on PATH ...

Useful Linux Commands - IV

who : gets all the connections made to your account netstat –antp : to know all the process running on ports sudo /etc/init.d/network restart : restart networking on your linux box Understanding the init.d Directory – This directory has the control scripts for most of the services on our linux box. The start/stop/restart/reload/force-reload options can be used with any command found under this directory Most common Services controllable from this directory are: apache2, sshd, networking, ftpd, samba, mysql You can run any command using the following format: sudo /etc/init.d/<command> <option> where command can be apache2, sshd, networking etc and option can be start, stop, restart etc For ex: sudo /etc/init.d/networking restart Simple! Refresh DNS Cache Ping your linux box using “ ping <your_computer_name> ” – Note down the IP Address shown Look at the contents of ifconfig file using “ sudo /sbin/ifconfig ” – Read the part labeled as inet addr: The t...

Useful Linux Commands - III

Here are some useful linux commands... whoami - This command gives you the userid you are logged in as pwd - print working directory. When you type in this command it tells you which folder you are in and along with printing the path of the folder ls - listing. This command will list out all the files and directories under the current directory sorted alphabetically ls -F - This command lists all the files and directories with directories displayed with a trailing slash and executables have a * at the end of the executable name ls -s - lists file sizes - displays in disk blocks ls -s -h lists file sizes with human readable file sizes wc - word count displays lines, words, characters for a particular file wc -c  wc -w wc -l cat - concatenate - prints the file contents one after another sort - sorts the output  head - - gets the topN results from a file mv - move - moves a file cp - copy - copies a file rm - removes a file rmdir - removes a directory cd - ch...

Useful Linux Commands - I

Want to know your system name? /bin/uname -n Know where you are in your file system:  pwd  The command will print Present Working Directory How do you create a shortcut in linux? ln How to extract compressed files? tar Downloading from a link can't be faster on any other OS :)  wget Forgot which commands you ran? history Want to see whats your disk space usage? df  df -h gives human formatted listing Most important command to know more about the above commands - Need more help about the commands? man