14
submitted 6 months ago* (last edited 6 months ago) by merompetehla@lemmy.ml to c/linux@lemmy.ml

upgrading xubuntu to 24.04, fresh install, but I'd like to copy the output of both dpkg -l and history to a usb stick.

About history: will it copy all commands I executed on all tabs? I work with several tabs simultaneously.

ETA: thank you for all your input, problem has been solved.

top 10 comments
sorted by: hot top controversial new old
[-] joyjoy@lemm.ee 10 points 6 months ago

First, use lsblk to list your block devices. Note the path containing your usb device. e.g. /dev/sdb1

Next mount the device to an existing folder or create a new one.

mkdir -p /mnt/thumbstick
mount /dev/sdb1 /mnt/thumbstick

Now you can pipe the dpkg output to the usb device.

dpkg -l > /mnt/thumbstick/packages.txt

Finally, you can unmount the stick to ensure everything is flushed. (optional)

umount /mnt/thumbstick
[-] merompetehla@lemmy.ml 1 points 6 months ago

thanks, this worked

[-] oo1@kbin.social 5 points 6 months ago

in case it's not clear from the comments . and sorry for repeating if it is, but this >> thing is a really useful terminal thing to know in many cases.
>>
will trap and redirect terminal output.

So consider any old commmand and its output:
echo abc

This invokes the echo command and echo outpts "abc" to terminal.

If we add on >> we can catch and redirect the output:

 echo abc >> blah.txt

Will capture the output "abc" into the file.

Note this is an APPEND operation, so run it twice to the same output file and you'll add more and more output to new lines at the end of the same file.

[-] bloodfart@lemmy.ml 4 points 6 months ago* (last edited 6 months ago)

plug in the usb, run the command lsblk. it will list all the block devices that the computer can see.

look for your usb by size, etc. the column "name" after lsblk will be the device and partition (for example sdc and sdc1). the "name" entry on the same line as your usb's size with a number after it is the partition, the one without a number is the usb itself. you will be mounting the partition.

make a directory in /var to mount the usb stick in with mkdir /var/usb. that command writes to the /var section of your filesystem, where /var-iable files live. mount the usb stick at that location with mount /dev/[your partition, like sdc1] /var/usb.

example: my usb was /dev/sdc1, so for me it's mount /dev/sdc1 /var/usb. the syntax is mount [device] [location].

run any command with |tee -i /var/usb/target_filename.txt after it to both output the command to the screen and send it to a file on the usb. that command writes the output of whatever command preceeds it to the specified file in /var/usb.

example: ls / |tee -i /var/usb/target_filename.txt would write the output of the command "ls /", listing the contents of the root of your filesystem, to /var/usb/target_filename.txt as well as displaying it. if /ver/usb/target_filesystem.txt doesn't exist, it will be created.

use different files on different commands so you don't write over what you have or pass -a to the tee command so it will -a-ppend the text it writes to the end of the file. ex: |tee -ia /var/usb/filename.txt

for the specific command you asked about, it would be dpkg -l |tee -i /var/usb/target_filename

to write out your command history, use the "history" command. it can be given the tee treatment as well. to access a users history look at their $HISTFILE. if you don't know what interpreter they're using, assume bash and look for ~/.bash_history

[-] merompetehla@lemmy.ml 1 points 6 months ago
[-] bloodfart@lemmy.ml 1 points 6 months ago

Did you get it straightened out?

[-] merompetehla@lemmy.ml 1 points 6 months ago
[-] visone@fosstodon.org 3 points 6 months ago* (last edited 6 months ago)

@merompetehla
Mount the usb in any directory
send the output of any command to a file
dpkg -l >> file.txt
Move those files to the directory were the usb is mounted

[-] lurch@sh.itjust.works 1 points 6 months ago* (last edited 6 months ago)

I'm pretty sure the history command outputs only commands from the shell/tab it's invoked in plus the commands already saved to the shells history file. Commands are not always saved to the file immediately. So to make 100% sure, you have to clean exit all shells before using history.

You can easily test this by using a unique command (like: echo 123) in one shell and history in another.

Also the shell probably has a man page detailing config options that affect the history.

[-] boredsquirrel@slrpnk.net 1 points 6 months ago

udisksctl for mounting.

this post was submitted on 28 May 2024
14 points (88.9% liked)

Linux

48376 readers
729 users here now

From Wikipedia, the free encyclopedia

Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).

Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.

Rules

Related Communities

Community icon by Alpár-Etele Méder, licensed under CC BY 3.0

founded 5 years ago
MODERATORS