• Skip to secondary menu
  • Skip to main content
  • Skip to primary sidebar

Python and R Tips

Learn Data Science with Python and R

  • Home
  • Python
  • Pandas
    • Pandas 101
  • tidyverse
    • tidyverse 101
  • R
  • Linux
  • Conferences
  • Python Books
  • About
    • Privacy Policy
You are here: Home / Basic Linux Commands / Basic Linux/Mac OS X Commands that Help You to Get Started

Basic Linux/Mac OS X Commands that Help You to Get Started

July 16, 2011 by cmdlinetips

Typically the learning curve of Linux commands is bit slow and scare people away from it. But the piece of advice that is worth is “Hang on!, You will see the fruits of your frustrations soon”.

Linux organizes everything in directories. For example, if you are a linux user, your account is just another directory. And inside each directory, you will have other directories. Often the most basic tasks in getting around the system involve creating a directory, changing to a directory, creating a file in a directory and so on.

Here are some basic linux/unix commands that lets you get started exploring the treasure beneath the terminal.

How to Find What is in a Directory?

Use the command “ls”, to find out what is inside a directory. “ls” basically means list and when you type “ls” from the current directory you are in, it will simply list the files and directories in that directory in alphabatic order.

Just like any other linux command, “ls” comes with loads of other options that you can use to get more information about the content in a directory.

For example, simply using “ls” does not give you information about the size of the files in the directory or the time it was created. To list the content of a directory with more options like mentioned above, use “ls” with the option “l”. The way to do it is

ls -l

This will result in a output containing each file/directory in a separate line. Without going into the details of the output, one can see that each line will tell you whether it is a file or directory, when was it created, who created it, size of the file/directory.

How to Create a New Directory?

If you are windows user, you might be calling directories as folders. The command to create a new directory is “mkdir”, which basically tells that “make directory”. For example, if you want to create a new directory named “Papers”, then type

mkdir Papers

How to Change or Move to a Directory

Often you might want to move (or change) to a directory from your home directory. The command to use to change the current working directory is “cd” and it basically means “change directory”. The way to use “cd” is to give the path to the new directory you want to change to. For example, if you are in your home directory and want to change to a directory named “Documents” that right in your home directory, you type

$cd Documents

This command will move you to the “Document” directory from your home directory.

How to Find the Type of a File?

Another common thing that one might to know is to view the content of an existing file. Before trying to view a file it is useful to know the type of the file, whether it is a text file or an image or a document like pdf. Typically, you will be able to tell the type of a file from the secondary name of a file. However, you might find yourself in a scenario you might more than that.

The command to find the type of a file using a terminal is “file”. Simply type “file” followed by the file name you will see information about the type of the file. For example,

$file vehile.pdf

will give you

$vehicle.pdf: PDF document, version 1.4

How to Rename or Move a File?

Another command one might need to use frequently is to rename an old file to a new file. The command to rename or move a file in command line in Linux or Mac OS X is “mv” (it basically means move). Here is how to use “mv” command to rename or move a file.

mv oldFile newFile

You can use “ls command before and after using the “mv” command and see what it has done.

How to Copy a File in Command Line?

The command to copy a file in command line in Linux or Mac OS X is “cp”, where “cp” basically means copy. Here is how to use “cp” command to copy a file.

cp oldFile newFile

A good practice while using “mv” or “cp” command is to use these commands with the option “-i”. The “-i” option will ask your permission to overwrite if the file you are exists already. And it helps you losing a potentially an important file. The way to use “mv” or “cp” with “-i” option is as follows

cp -i oldFile newFile

How to Remove a File?

Removing a file is definitely the important and powerful command in Linux or Mac OS X. The key to remember here is that, in general, if you remove a file it is gone for ever (unless it is backed up somewhere else). Exercise caution while removing a file. The command to remove a file using terminal is “rm”, which simply means “remove” just like other commands. A good practice is to use with “-i” option.

rm -i myFile

Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X

Related posts:

Tips to Get Started with Screen, the Terminal Multiplexer Default ThumbnailHow to Find the List of Directories in a Directory in Linux/Mac OS X? Default Thumbnail12 Basic Commands with NumPy Array Default ThumbnailTen Linux Commands on “tar” and “gzip” You Need to Know

Filed Under: Basic Linux Commands, Linux Tips Tagged With: Create Directory, Linux Commands

Primary Sidebar

Subscribe to Python and R Tips and Learn Data Science

Learn Pandas in Python and Tidyverse in R

Tags

Altair Basic NumPy Book Review Data Science Data Science Books Data Science Resources Data Science Roundup Data Visualization Dimensionality Reduction Dropbox Dropbox Free Space Dropbox Tips Emacs Emacs Tips ggplot2 Linux Commands Linux Tips Mac Os X Tips Maximum Likelihood Estimation in R MLE in R NumPy Pandas Pandas 101 Pandas Dataframe Pandas Data Frame pandas groupby() Pandas select columns Pandas select_dtypes Python Python 3 Python Boxplot Python Tips R rstats R Tips Seaborn Seaborn Boxplot Seaborn Catplot Shell Scripting Sparse Matrix in Python tidy evaluation tidyverse tidyverse 101 Vim Vim Tips

RSS RSS

  • How to convert row names to a column in Pandas
  • How to resize an image with PyTorch
  • Fashion-MNIST data from PyTorch
  • Pandas case_when() with multiple examples
  • An Introduction to Statistical Learning: with Applications in Python Is Here
  • 10 Tips to customize ggplot2 title text
  • 8 Plot types with Matplotlib in Python
  • PCA on S&P 500 Stock Return Data
  • Linear Regression with Matrix Decomposition Methods
  • Numpy’s random choice() function

Copyright © 2025 · Lifestyle Pro on Genesis Framework · WordPress · Log in

Go to mobile version