lftp usage on Linux

This post introduces lftp usage on Linux.

(Thanks Scott for sharing this nice tool.)

lftp is a command-line program client for several file transfer protocols. lftp is designed for Unix and Unix-like operating systems.

1: Installation on Ubuntu:

$ sudo apt-get update
$ sudo apt-get install lftp

2: Some commonly used commands with lftp:

ls  — list direcotries and files on remote ftp server

cd — change directory on remote ftp server

lpwd — list local machine current directory

lcd — change local directory

mput *.csv  — mput for multiple files, put for a single specific file.

This will take from the current local directory  and put into the current remote directory on  remote ftp server.

copy directory and its contents to and from ftp server (from and to local machine):

mirror -c -R  path/to/localdirectory/   

This will copy local directory to (the current directory) on the  remove ftp server  , c means continue)

       mirror -c  path/to/remote/directory

This will copy the remote directory  to (the current local directory  , c means continue)

(for more commands, check the lftp man page provided in the references below.)

3: Using Box under Linux (using lftp)

The lftp command is a powerful file transfer client that can be used with Box.

Box supports the secure FTPS protocol and you can use this with lftp for secure file transfer and mirroring.

The lftp command is smart enough to auto-negotiate to use FTPS but this example forces the issue to make absolutely sure unencrypted FTP is never attempted.

Here is an example of how to connect using FTPS.

$ lftp
lftp :~> set ftps:initial-prot ""
lftp :~> set ftp:ssl-force true
lftp :~> set ftp:ssl-protect-data true
lftp :~> open ftps://ftp.box.com:990
lftp ftp.box.com:~> user yourusername@psu.edu
lftp yourusername@psu.edu@ftp.box.com:~> ls


when finish use exit to exit from lftp.

4: Copy a remote folder via FTP on the Linux command line using lftp (PDF)



lftp Man page (PDF)

Using Box under Linux (PDF)

For more commonly used Linux commands, check my other posts at here  and here .


Find all files containing specific text on Linux and Mac

This post introduces how to find all files containing some text on Linux and Mac.

Step 1: cd to the folder where you would like to start with the search.

Step 2: use the following command:

$ grep -Ril "text-to-find-here" ./

Then the file names containing the text you would like to search will be listed.

  • R — stands for recursive.
  • i —  ignore case (optional in your case).
  • l — stands for “show the file name, not the result itself”.

For more commonly used Linux commands, check my other posts at here  and here .

Get top or bottom 10 files under a director from terminal (on Ubuntu and Mac)

This post get top/bottom 10 from the sorted file names in current directory.

For reading the first line of a file from terminal (on Ubuntu and Mac), check here.

Note: you do not need to install anything, it is built-in on your Ubuntu/Mac OS.

Step 1: open a terminal 

Step 2: cd to the directory where your file (e.g., .txt file) is located 

Step 3: issue the following command accordingly

$ ls | head -10

# the pipe symbol (i.e., |) puts the output of the ls command as the input of the head command.

if you would like to get more information of the files, use the following instead:

$ ls -l | head -10


if you would like to get the bottom 10 files in the current directory, issue the following command:

$ ls | tail -10

or for detailed information of the files, use

$ ls -l | tail -10

You guessed it, if you would like to get the top/bottom 20, just change the -10 to -20:)

simply, enough, right?


For more commonly used Linux commands, check my other posts at here  and here .

The differences between su – and su on Linux

This post introduces the difference between su – and su.

su - logs you in completely as root, whereas su makes it so you are pretending to be root.

The most obvious example of this is that ~ is root’s home directory if you use su -, but your own home directory if you use su.

Depending on your system, it may also mean differences in prompt, PATH, or history file.

Check here for more detailed discussion (PDF).


Run a shell script at startup / reboot

This post introduces how to auto run a shell script when your machine reboot.

We can set a crontab for this.

The crontab (short for “cron table”) is a list of commands that are scheduled to run at regular time intervals on your computer system. The crontab command opens the crontab for editing, and lets you add, remove, or modify scheduled tasks.

Just have a line added to your crontab.

Make sure the sh file is executable (you can use the following command to make the file executable)

$ chmod +x /path_to_you_file/your_file

To edit crontab file, enter the following command in your terminal:

$ crontab -e
# Edit your crontab.

The line you need to add:

@reboot  /path_to_you_file/your_file

for example,

@reboot  /home/user/test.sh

after every startup it will run the test.sh script.

To save and exit your crontab from vim,


Use the following command to confirm that it is actually been set.

$ crontab -l
# Display ("list") the contents of your crontab.

this will show @reboot sh $HOME/test.sh

To see whether the app that the .sh starts is actually running, you can use ps -ef (check here for more details about ps -ef).

Reboot the server to confirm whether it all works.


Linux crontab command (PDF)

Linux at, batch, atq, and atrm commands (PDF)

How to run a shell script at startup (PDF)