Basic commands on FreeBSD

FreeBSD has more than 650 commands and every command has its own set of options all performing different operations. Going through each and every one of these commands will be a very tedious task. However limiting yourself to only a few of them is never an option.



Directory Commands

    • pwd : Print working directory
    • mkdir :  Create directories
    • cd : Change the current directory
    • rmdir   : Remove directories


File Commands

    • ls : List directory contents
    • rm : Remove files
    • cp : Copy files from a source to the same or different target(s).
    • mv : Move file to different targets.
    • cat : Read one or more files and print them to standard output. If you need to

view  contents of a short file, cat is recommended.

    • cmp: Compare two files byte by byte.
    • wc: Print the number of new lines, words, and bytes in files.
    • du : Estimate disk usage of each file and recursively for directories.
    • find: Search for files in directory hierarchy, e.g. find notes.txt
    • grep: Print lines matching a pattern,e.g. grep –i topic notes.txt (topic is the pattern)
    • sort: Sort lines of text files



Every Linux program is an executable file. For instance, the cp command is provided by the file in /bin/sh which holds the list of machine instructions. Similarly, if you are installing a package , let’s say vsftpd, your focus will be modifying its configuration file , vsftpd.conf present in /etc directory. This is where you will be using editors.

I use ‘Vim’ frequently. It’s an advanced text editor that comes with a more complete feature than the ‘Vi’ text editor. The other text editors are: nano, ee, vi, vim.


e.g.  vim  rabi.c ( vim filename ).


User Account


  • passwd : for changing user password.

If the user has set password before, he/she will be prompted for the first password whereas superuser is permitted to bypass the step so that forgotten passwords may be changed.

You can find advices on how to choose a strong password on

  • chmod :   modify properties for users
  • chown : change file owner and group
  • chgrp :   change group ownership

Network Commands


wget   : a non-interactive network downloader

Even if a download fails due to a network problem, it will keep retrying until the whole file has been retrieved.   The server will instruct to continue to download from where it  it left off.

$ wget url-for-file

ping  : send ICMP ECHO_REQUEST to network hosts, you will get back ICMP packet if the host responds.  This command is useful when you are in a doubt whether your computer  is connected or not.

$ ping IP or host name


hostname  : show or set  the system’s host name

dnsdomainname : show the system’s DNS domain name

netstat : displays the status of ports ie. which ports are open, closed,       waiting for connections. It displays the contents of /proc/net file.

ifconfig : configure a network interface, or to display their current configuration. It is also useful to get the information about IP address, Subnet Mask,set remote IP address , Netmask etc.

sockstat -l4 : list open sockets



Archive Commands


tar : an archiving program designed to store and extract files from an archive known as a tarfile.

Options :

-c : create a new archive

-r : append files to the end of an archive

-t : list the contents of an archive

-u : only append files that are newer than copy in archive

-x : extract files from an archive

-C : change to directory Dir

-j : filter archive through bzip2,  use  to  decompress  .bz2  files.

-v : verbosely list files processed

-f : use  archive  file

-z : filter the archive through gzip

Examples: tar  -xvf  test.tar    ( extract foo.tar to the current location)

tar -xvzf  test.tar.gz  ( extract gzipped test.tar.gz )

tar  -cvf test.tar    foo/ ( compress the contents of foo folder to foo.tar )



unzip : extract files from a ZIP archive


unrar :  extract files from a RAR archive


unarj :  extract files from a ARJ archive



Help commands

There are manual pages for almost all the commands of FreeBSD. You can access the manual pages using man command. The man command offers documentation of the command.  If you type:

$ man ls



Process commands


In order to execute a command in the background, place an ampersand(&) on the command line at the end of the command. A user job number(placed in brackets) and a system process number are displayed. A system process number is the number by which the system identifies the job whereas a user job number is the number by which the user identifies the job.

$ sudo cp -rf * ~/ss &

[1]   9144


  • jobs : lists the jobs being run at the background


[1]-  Running   sudo  cp  -rf  *  ~/ss  &

[2]+  Running   sudo  cp  -rf  *  ~/yy &

  • The ‘+‘ sign  indicates the job currently being processed , ‘-’ sign indicates the upcoming jobs to be executed.  The ‘% ‘ used with the job number refrences a job. e.g. Used in fg.
  • fg : a  process running in the background  will be processed in the foreground

$ fg % 2

cat  *.cpp  > mytext


  • kill : cancels a job running in the background, it takes argument either the user job number or the system process number.


[1]   +  Running    cp  *.c  > mytext

[2]  - Running    cp  *.dat >>mytext

$kill %2

  • bg: places a suspended job in the background

$ cat *.cpp > mytext



( Ctrl + Z  will suspend the process running at the moment )

  • ps : reports a snapshot of the current processes
  • top : displays Linux tasks
  • at : executes commands at a specified time.

$ at  8:00

at >  echo “HI” > /dev/tty1

(Press ‘ctrl + d’ to return to the command line. This will display the message in tty1 at 8′o clock.)

  • To view the schedule : $ atq
  • To cancel a job : $atrm 5   [job ID]
  • crontab :crontab  is a file which contains the schedule of  entries to run at  specified times.
  • shutdown : bring the system down
    • -r     Requests  that  the system be rebooted after it has been brought down.
    • -c     Cancels a running shutdown.

Other commands


  • whoami : displays the login name of the current effective user.
  • logname : print user´s login name
  • quota : display disk usage and limits, e.g $ quota -v
  • su : switch to super user or change user ID
  • which : returns the pathnames of the files which would be executed in the current  environment.

Type $which ls, you will get /bin/ls.

Live Free Or Die!