Creating directory on an external hard drive via command line (SSH) on Linux

30,032

Solution 1

You need to mount the drive first.

mount /dev/sda1 /mnt

then make your directory

cd /mnt
mkdir some-directory

This may help but I haven't watched it.

Side note: You may need to format the drive or partition it with something Linux can read and write. NTFS support in Linux is pretty mature, but for quite some time you could only mount it read only without possible data loss. If that is still the case then you will need to partition and format it with something more friendly.

Solution 2

I don't know too much as i am just a newbie in linux but this works for my pc.Open properties of your external device see location there.

in my case it is

/media/username

where username is my home directory name(It will be different in your case)

in terminal just enter

cd /media/username/exter1

where exter1 is my external drive name.

now just make directory there.

mkdir dirname

Solution 3

You can see with df or mount where /dev/sda1 is mounted. Then go there with cd and create your directory with mkdir. depending on how the disk got mounted (with which user), the mkdir might need a sudo.

Share:
30,032
KeirDavis
Author by

KeirDavis

Updated on September 18, 2022

Comments

  • KeirDavis
    KeirDavis almost 2 years

    I have tried many approaches to create a directory on my external hard drive. Here is the details when I do

    fdisk -l
    

    What I get:

    pi@raspberrypi:~$ sudo fdisk -l
    
    Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes
    4 heads, 16 sectors/track, 121008 cylinders, total 7744512 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x000a589c
    
            Device Boot      Start         End      Blocks   Id  System
    /dev/mmcblk0p1            2048     2464843     1231398    e  W95 FAT16 (LBA)
    /dev/mmcblk0p2         2465792     7744511     2639360   85  Linux extended
    /dev/mmcblk0p5         2473984     2588671       57344    c  W95 FAT32 (LBA)
    /dev/mmcblk0p6         2596864     7744511     2573824   83  Linux
    
    Disk /dev/sda: 320.1 GB, 320072933376 bytes
    255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0xbe707a93
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *          63   625137344   312568641    7  HPFS/NTFS/exFAT
    

    I found that my external hard drive is most likely located at /dev/sda so I tried 'cd'ing to it, but came to a dead end when it says

    pi@raspberrypi:~$ cd /dev/sda
    

    -bash: cd: /dev/sda: Not a directory

    Any help with getting on with my task?

  • KeirDavis
    KeirDavis over 10 years
    pi@raspberrypi:~$ sudo mount /dev/sda1 /mnt mount: /dev/sda1 already mounted or /mnt busy mount: according to mtab, /dev/sda1 is already mounted on /mnt -I got from PuTTY
  • SarahG
    SarahG over 10 years
    The cd /mnt and make your directory
  • KeirDavis
    KeirDavis over 10 years
    I have to sudo because of permissions, but I get pi@raspberrypi:~$ sudo cd /mnt mkdir some-directory sudo: cd: command not found (EDIT) Fixed it, used 'sudo -i' and did it! Thanks!
  • Michael Suelmann
    Michael Suelmann over 10 years
    cd does not work with sudo as it is a shell internal command.