Posts tagged unix

Fix ^M in Linux/UNIX using vi/vim

Sometimes if you edit a file in windows and then open it in Linux/UNIX it will have the special characters ^M at the end of each sentence. To fix ^M in Linux/UNIX using vi/vim run the following:

%s/[ctrlkey+v and ctrl-key+M]//g

sed tricks to replace multi blank spaces and tabs with single space

Replace all multi-blankspaces (more than one spaces/tabs) in file with mono-blankspace (one space):

sed 's/[<space>][<tab>][<space>][<tab>]*/ /g' filename

can also be:

 sed 's/[<space>][<tab>][<space>][<tab>]*/ /g' filename > newfilename

note: g in the end means GLOBAL

In the above samples, <space> means ‘ ‘ (empty space) and <tab> means ‘      ‘ (tab key press).

Execute process in Linux/UNIX to run in the background by using NOHUP

If you need to execute a process that will run in the background so that it does not lock one terminal window then you should try using the NOHUP command.

Example usage:

nohup <command here> &

After executing it, a nohup.out file will be created (append if it exists) which will contain all the output from the command (if any).

However, if you want to close the terminal window, like if you are working on a remote machine, do the following:

(nohup <command here> & ) &

This will disconnect the process from your session completely so you should be able to close the terminal window and do not interrupt the process.

To check if the process is still running, perform the following:

ps -ef|grep -i <command name or part of command name>

This is listing all the processes on the machine and then grepping for the command name with case insensitive (-i).

If you want to stop the process, you will need to kill it with the following command:

kill <process id>

The process-id can be seen from running the ps command above. In most instances it is the first number of the row.

If the process hangs after the kill command, do force kill:

kill -9 <process id>

This will kill any process, so please double check the process id before executing it.

Go to Top