# Copying a directory



## Deleted member 67029 (Jul 6, 2021)

How does one copy a directory? I tried the following command, but it didn't work:

cp foo/ bar/


----------



## Criosphinx (Jul 6, 2021)

cp -R foo/bar

cp()


----------



## Deleted member 67029 (Jul 6, 2021)

This command did not work:

cp -R foo/bar


----------



## Deleted member 67029 (Jul 6, 2021)

Why is FreeBSD refusing to copy these three files?


----------



## Criosphinx (Jul 6, 2021)

¿Did you read the manual page?


----------



## Deleted member 67029 (Jul 6, 2021)

Some of it.


----------



## mer (Jul 6, 2021)

See that part that says "socket not copied"?  It's not copied because it's a socket.  Why not copy sockets?  Because sockets are transient entites, simply a pipe for communications and copying them makes no sense.


----------



## Deleted member 67029 (Jul 6, 2021)

It looks like a file to me, but ok. Thanks


----------



## mer (Jul 6, 2021)

Kolusion said:


> It looks like a file to me, but ok. Thanks


Fundamental paradigm of Unix and all Unix-like systems:
Everything is a file or looks like a file, but it may not actually be what a user would think of as "a file".

when you "ls" a directory, you are simply seeing a list of "named things" in that directory.  A directory is also a "named thing" which is why they also show up when you do "ls".

If you want more information about what a named thing may be, use the command "file".  For information about that command and other commands, use the command "man"  (short for "manual pages", also known as "help"):

man file
man man

That is basic information about just about any Unix or Unix-like system you may run across.


----------



## Deleted member 67029 (Jul 6, 2021)

Thank you


----------



## ralphbsz (Jul 6, 2021)

Kolusion said:


> It looks like a file to me, but ok. Thanks


Try "ls -F", it decorates every file system object with what kind of thing it is in its output. Regular files don't get decorated at all. Executable files get a "*" behind them. Directories get a trailing slash like "dir/". Soft links get an "@". And strange file system entries (devices, socket, fifos, ...) get stranger characters.

Obviously, this works best if your file names don't contain such special characters. But there are good reasons to not use special characters in file names: While technically any character other than "/" and NUL is legal in file names, special characters will cause confusion. For example, look on the internet for the story of the boy who created a file called "*", and tried to delete it with "rm *". Oops.


----------



## drhowarddrfine (Jul 6, 2021)

ralphbsz He's dead, Jim


----------



## grahamperrin@ (Jul 8, 2021)

Kolusion said:


> It looks like a file to me, …



Hints: 


```
root@mowa219-gjp4-8570p:~ # file /var/run/log
/var/run/log: socket
root@mowa219-gjp4-8570p:~ #
```

`man 1 file`


```
root@mowa219-gjp4-8570p:~ # bfs -s -type s /var/run
/var/run/devd.pipe
/var/run/devd.seqpacket.pipe
/var/run/log
/var/run/logpriv
/var/run/cups/cups.sock
/var/run/dbus/system_bus_socket
/var/run/user/1002/kdeinit5__0
/var/run/user/1002/klauncheriYzkqN.1.slave-socket
/var/run/user/1002/vscode-f8b69df7-1.56.2-main.sock
/var/run/user/1002/vscode-git-6c564a3a88.sock
/var/run/user/1002/akonadi/akonadiserver-cmd.socket
/var/run/user/1002/akonadi/akonadiserver-ntf.socket
/var/run/user/1002/keyring/control
root@mowa219-gjp4-8570p:~ #
```

sysutils/bfs


----------

