Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Aug 272011
 

Edit a remote file with vim over SSH

Answer:

If you have a remote file and you can have a quick edit, if you use the following command:

# ssh -t john@remote-server vim /data/test.txt

You will be prompted to login if you don't have proper ssh key in the remote server, and after finishing editing the file, you will quit the ssh session automatically.

Jun 152011
 

Auto create complete directory structure when copying files in Linux

Answer:

Assume you are copying file using the command below:

# cp foo/bar/test.txt /tmp/

The result is test.txt will be placed inside the folder /tmp/.

In order to let the cp command auto create the foo/bar/ directory structure under /tmp, you can try the command:

# cp --parent foo/bar/test.txt /tmp/

Jan 212011
 

Simple date calculation using date command

Answer:

Date command is useful to calculate date, e.g. Assume today is 2011-01-15

1. Find a date in the past, e.g. 60 days ago

# date --date='60 days ago' "+%Y-%m-%d"
2010-11-16

2. Find a date in the future, e.g. 60 days in the future

# date --date='60 days' "+%Y-%m-%d"
2011-03-16