Linux para principiantes: 10 comandos más para manipular archivos

En caso de que se haya perdido el primer segmento de esta serie de dos partes, hemos analizado 10 comandos para que pueda comenzar a usar Terminal. Ahora, exploraremos 10 comandos más que puede usar para continuar su viaje de línea de comandos. Específicamente, quiero examinar los comandos usados para manipular archivos. Vamos a copiar, mover y renombrar archivos, así como algunos comandos para reproducir archivos de diferentes formas.
Comandos para saber
1.cp archivo1 archivo2
el Copiar El comando se utiliza para copiar el contenido de un archivo a otro. También puede usar este comando para copiar un archivo de un directorio a otro.
[[email protected] community_content]$ ls -l
total 36
-rw-rw-r--. 1 tcarrigan tcarrigan 5 Feb 6 2020 article
-rw-rw-r--. 1 root tcarrigan 5 Feb 6 2020 article2
-rw-rw-r--. 1 root tcarrigan 5 Feb 6 2020 article3
-rw-rw-r--. 1 tcarrigan tcarrigan 5 Feb 6 2020 article4
-rw-rw-r--. 1 tcarrigan tcarrigan 6404 Apr 7 2020 podman_pulling
-rw-rw-r--. 1 tcarrigan tcarrigan 8824 Apr 7 2020 real_sysadmins
[[email protected] community_content]$ cp podman_pulling article
[[email protected] community_content]$ ls -l
total 40
-rw-rw-r--. 1 tcarrigan tcarrigan 6404 Oct 26 19:11 article
-rw-rw-r--. 1 root tcarrigan 5 Feb 6 2020 article2
-rw-rw-r--. 1 root tcarrigan 5 Feb 6 2020 article3
-rw-rw-r--. 1 tcarrigan tcarrigan 5 Feb 6 2020 article4
-rw-rw-r--. 1 tcarrigan tcarrigan 6404 Apr 7 2020 podman_pulling
-rw-rw-r--. 1 tcarrigan tcarrigan 8824 Apr 7 2020 real_sysadmins
Como puedes ver, copié el podman_tirando contenido del artículo en ít archivar. Ahora, la otra cosa que puede hacer con este comando es copiar un archivo existente a otro directorio. Por ejemplo, si quisiera copiar el podman_tirando artículo en mi directorio de inicio, haría algo como esto:
[[email protected] community_content]$ cp podman_pulling /home/tcarrigan/
** Navigate to /home/tcarrigan **
[[email protected] ~]$ ls -l
total 8
drwxrwxr-x. 4 tcarrigan tcarrigan 50 Feb 6 2020 article_submissions
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Desktop
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Documents
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Downloads
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Music
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Pictures
-rw-rw-r--. 1 tcarrigan tcarrigan 6404 Oct 26 19:17 podman_pulling
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Public
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Templates
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Videos
Puedes ver eso podman_tirando ya está disponible en mi /home/tcarrigan
directorio telefónico.
2.mv archivo1 archivo2
el movimiento El comando permite a un usuario mover o cambiar el nombre de un archivo. Para mover un archivo, usaría lo siguiente:
[[email protected] ~]$ mv podman_pulling article_submissions/my_articles/
[[email protected] ~]$ ls -l article_submissions/my_articles/
total 20
-rw-rw-r--. 1 tcarrigan tcarrigan 4442 Apr 7 2020 Creating_physical_volumes
-rw-rw-r--. 1 tcarrigan tcarrigan 2744 Apr 7 2020 Creating_volume_groups
-rw-rw-r--. 1 tcarrigan tcarrigan 6404 Oct 26 19:17 podman_pulling
moví el podman_tirando artículo de mi directorio personal a /article_submissions/my_articles
. Ahora digamos que necesitamos cambiar el nombre del artículo a "podman_tirando" en "podman sin raices. "¿Cómo haríamos eso?
[[email protected] my_articles]$ mv podman_pulling rootless_podman
[[email protected] my_articles]$ ls -l
total 20
-rw-rw-r--. 1 tcarrigan tcarrigan 4442 Apr 7 2020 Creating_physical_volumes
-rw-rw-r--. 1 tcarrigan tcarrigan 2744 Apr 7 2020 Creating_volume_groups
-rw-rw-r--. 1 tcarrigan tcarrigan 6404 Oct 26 19:17 rootless_podman
3.ln -s enlace de archivo
el Enlace El comando en este contexto nos permitirá crear un enlace simbólico o enlace simbólico a otro archivo o directorio. Para obtener más información sobre este tema, consulte mi artículo anterior. Por ahora, solo mostraré cómo usar el comando de enlace suave.
[[email protected] ~]$ ln -s article_submissions/community_content/podman_pulling podman_article
[[email protected] ~]$ ls -l
total 0
drwxrwxr-x. 4 tcarrigan tcarrigan 50 Feb 6 2020 article_submissions
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Desktop
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Documents
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Downloads
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Music
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Pictures
lrwxrwxrwx. 1 tcarrigan tcarrigan 52 Oct 27 13:51 podman_article -> article_submissions/community_content/podman_pulling
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Public
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Templates
drwxr-xr-x. 2 tcarrigan tcarrigan 6 Jan 27 2020 Videos
Esto crea un enlace en mi directorio de inicio a la /home/tcarrigan/article_submissions/community_content/podman_pulling
archivo, lo que significa que puede leer artículo_podman y se abrirá el archivo dentro del contenido_comunitario directorio telefónico.
4.toca el archivo
Utilizar el tocar comando para crear o actualizar un archivo (aquí creo archivo nuevo en el mis_articulos directorio telefónico).
[[email protected] my_articles]$ touch new_file
[[email protected] my_articles]$ ls -l
total 20
-rw-rw-r--. 1 tcarrigan tcarrigan 4442 Apr 7 2020 Creating_physical_volumes
-rw-rw-r--. 1 tcarrigan tcarrigan 2744 Apr 7 2020 Creating_volume_groups
-rw-rw-r--. 1 tcarrigan tcarrigan 0 Oct 28 16:47 new_file
-rw-rw-r--. 1 tcarrigan tcarrigan 6404 Oct 26 19:17 rootless_podman
Tenga en cuenta que la marca de tiempo del archivo creado es 16:47. ahora voy a usar el tocar Comando para actualizar la marca de tiempo a la hora actual (19:35).
[[email protected] my_articles]$ touch new_file
[[email protected] my_articles]$ ls -l
total 20
-rw-rw-r--. 1 tcarrigan tcarrigan 4442 Apr 7 2020 Creating_physical_volumes
-rw-rw-r--. 1 tcarrigan tcarrigan 2744 Apr 7 2020 Creating_volume_groups
-rw-rw-r--. 1 tcarrigan tcarrigan 0 Oct 28 19:35 new_file
-rw-rw-r--. 1 tcarrigan tcarrigan 6404 Oct 26 19:17 rootless_podman
5.cat > archivo
Este comando se usa para ingresar la salida estándar a un archivo. Ingresaré "Hello World" en el archivo archivo_prueba
[[email protected] ~]$ cat > test_file
Hello World
Usar Ctrl+D* para terminar de editar el archivo. Para visualizar su trabajo, puede utilizar el estándar cat filename
sintaxis.
[[email protected] ~]$ cat test_file
Hello World
6.más archivo
el Siguiente El comando permitirá al usuario ver el contenido de un archivo una pantalla a la vez. Aquí veremos la /article_submissions/my_articles/creating_physical_volumes
archivar.
# How to create a physical volume in Linux using LVM
by Tyler Carrigan
Physical volumes `PV` are the base 'block' that you need in order to manipulate a disk using Logical Volume Manager `LVM`. Now, let's not rush ahead. What exactly is a physical volume? What in the world i
s LVM? In short, LVM is a type of Almacenamiento Virtualización that allows operators far more flexibility in Almacenamiento management than standard partitioning. A physical volume is any physical Almacenamiento device, such
as an Hard Disk Drive `HDD`, Solid State Drive `SSD`, or partition, that has been initialized as a physical volume with LVM. Without properly initialized physical volumes, you cannot create Volume Groups
or logical volumes.
So lets get started! First, there are a few considerations.
Dont try to pinpoint the exact amount of space you need down to the nearest byte. The reason for this is that LVM places labels on the physical volumes `UUID` as well as metadata Almacenamiento. While this doesn
t take up very much space, understand that if you initialize a 1Gb PV, you do **not** have 1Gb of *usable* space.
** Output Omitted **
Puede ir línea por línea con el Entrar clave o página por página con Espacio. Otra opción útil es la -número opción que le permite especificar el número de líneas mostradas por página.
Para mostrar 10 líneas a la vez, puede usar more -10 filename
. Puedes usar el + firme para especificar desde qué línea comenzar: more +10 filename
.
7. menos archivo
el menos El comando permite al usuario la misma funcionalidad que Siguiente. Sin embargo, es más rápido porque no carga el archivo completo sino que permite al usuario escanear el archivo usando las teclas de flecha. Esto es especialmente notable en archivos de registro grandes.
[[email protected] my_articles]$ sudo less /var/log/messages
Oct 26 19:50:47 server dbus-daemon[939]: [system] Activating via systemd: service name="org.freedesktop.nm_dispatcher" unit="dbus-org.freedesktop.nm-dispatcher.service" requested by ':1.15' (uid=0 pid=1155 comm="/usr/sbin/NetworkManager --no-daemon " label="system_u:system_r:NetworkManager_t:s0")
Oct 26 19:50:47 server systemd[1]: Starting Network Manager Script Dispatcher Service...
Oct 26 19:50:47 server dbus-daemon[939]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'
Oct 26 19:50:47 server systemd[1]: Started Network Manager Script Dispatcher Service.
** Output Omitted **
archivo 8.head
el dirigir El comando permite al usuario generar las primeras 10 líneas de cualquier archivo. Usaré el ejemplo de creating_physical_volumes
.
[[email protected] my_articles]$ head Creating_physical_volumes
# How to create a physical volume in Linux using LVM
by Tyler Carrigan
Physical volumes `PV` are the base 'block' that you need in order to manipulate a disk using Logical Volume Manager `LVM`. Now, let's not rush ahead. What exactly is a physical volume? What in the world is LVM? In short, LVM is a type of Almacenamiento Virtualización that allows operators far more flexibility in Almacenamiento management than standard partitioning. A physical volume is any physical Almacenamiento device, such as an Hard Disk Drive `HDD`, Solid State Drive `SSD`, or partition, that has been initialized as a physical volume with LVM. Without properly initialized physical volumes, you cannot create Volume Groups or logical volumes.
So lets get started! First, there are a few considerations.
Dont try to pinpoint the exact amount of space you need down to the nearest byte. The reason for this is that LVM places labels on the physical volumes `UUID` as well as metadata Almacenamiento. While this doesnt take up very much space, understand that if you initialize a 1Gb PV, you do **not** have 1Gb of *usable* space.
Also, although LVM allows you to create physical volumes using multiple partitions, it is recommended that you use a single partition for a PV. This is for a couple of reasons.
[[email protected] my_articles]$
9. archivo de cola
el cola El comando permite al usuario ver las últimas 10 líneas de cualquier archivo. aquí vamos a mirar /var/log/messages
.
[[email protected] my_articles]$ sudo tail /var/log/messages
[sudo] password for tcarrigan:
Oct 28 20:17:47 server org.gnome.Shell.desktop[2053]: Window manager warning: last_user_time (9080279) is greater than comparison timestamp (9080269). This most likely represents a buggy client sending inaccurate timestamps in messages such as _NET_ACTIVE_WINDOW. Trying to work around...
Oct 28 20:17:47 server org.gnome.Shell.desktop[2053]: Window manager warning: W1 appears to be one of the offending windows with a timestamp of 9080279. Working around...
Oct 28 20:17:48 server dbus-daemon[948]: [system] Activating via systemd: service name="net.reactivated.Fprint" unit="fprintd.service" requested by ':1.500' (uid=0 pid=5259 comm="sudo tail /var/log/messages " label="unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023")
Oct 28 20:17:48 server systemd[1]: Starting Fingerprint Authentication Daemon...
Oct 28 20:17:49 server dbus-daemon[948]: [system] Successfully activated service 'net.reactivated.Fprint'
Oct 28 20:17:49 server systemd[1]: Started Fingerprint Authentication Daemon.
Oct 28 20:17:53 server org.gnome.Shell.desktop[2053]: Window manager warning: last_user_time (9086680) is greater than comparison timestamp (9086677). This most likely represents a buggy client sending inaccurate timestamps in messages such as _NET_ACTIVE_WINDOW. Trying to work around...
Oct 28 20:17:53 server org.gnome.Shell.desktop[2053]: Window manager warning: W1 appears to be one of the offending windows with a timestamp of 9086680. Working around...
Oct 28 20:18:00 server org.gnome.Shell.desktop[2053]: Window manager warning: last_user_time (9093426) is greater than comparison timestamp (9093424). This most likely represents a buggy client sending inaccurate timestamps in messages such as _NET_ACTIVE_WINDOW. Trying to work around...
Oct 28 20:18:00 server org.gnome.Shell.desktop[2053]: Window manager warning: W1 appears to be one of the offending windows with a timestamp of 9093426. Working around...
[[email protected] my_articles]$
10. cola -f archivo
el -F variante de la cola La orden es una versión completamente diferente de la orden original. Esta bandera permite al usuario ver el archivo tal como está escrito. Esto es increíblemente útil para solucionar problemas de inicio/apagado de aplicaciones y sistemas.
ahora ya sabes
Si ha seguido este tutorial, debería tener 10 comandos más en el arsenal de su terminal. Desde mover, copiar, crear y actualizar hasta varias formas de leer el contenido de los archivos, debe sentirse cómodo moviéndose por el sistema de archivos y manipulando archivos y directorios que encuentre. Si esto te parece complicado, sigue practicando y serás un usuario más seguro en poco tiempo. Para obtener más consejos, trucos y herramientas, vuelva a contactarnos y active Sysadmin.
Artículos de interés