0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Linux Tips

0
Last updated at Posted at 2024-09-30

SDカードのマウント

SD内でパーティション作成するだけだと、マウントできない

以下を行う必要がある

  1. SDカード内にパーティションを作成(e.g. sudo fdisk /dev/sda)
  2. パーティションをファイルシステム指定してフォーマット(e.g. sudo mke2fs -t ext4 /dev/sda1)
  3. パーティションをマウント(e.g. sudo mount /dev/sda1 /mnt)

ログイン管理

# session一覧を表示
$ loginctl list-sessions
# sessionを終了させる
$ loginctl terminate-session <sessionID>

リモートデスクトップ切断でセッション削除
以下を設定systemctl restart xrdp

/tec/xrdp/sesman.ini
...
KillDisconnected=true
...

proxy下でapt-get

以下のファイルを作成。(環境変数にproxy設定書いてもapt-getでは見てなさそう

/etc/apt/atp.conf
Acquire::ftp::proxy "ftp://<ipaddr>:<port>/";
Acquire::http::proxy "http://<ipaddr>:<port>/";
Acquire::https::proxy "https://<ipaddr>:<port>/";

出力結果をクリップボードにコピーする方法

ls -al | xclip -selection clipboard

※マウスの選択範囲をクリップボードにコピー:xclip -selection primary

sedとxargsでまとめて指定する方法

例えば、以下の変更から「journal」がつくファイルのみのdiffがほしい場合

$ git status
ブランチ v250-stable
このブランチは 'origin/v250-stable' に比べて397コミット遅れています。fast-forwardすることができます。
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   src/core/systemd.pc.in
        modified:   src/journal-remote/journal-remote-write.c
        modified:   src/journal/journald-server.c
        modified:   src/libsystemd/sd-journal/journal-file.c
        modified:   src/libsystemd/sd-path/sd-path.c
        modified:   src/login/logind.conf.in
        modified:   src/resolve/test-resolved-stream.c
        modified:   src/systemctl/systemd-sysv-install.SKELETON
        modified:   tmpfiles.d/tmp.conf
        modified:   units/meson.build
        modified:   units/proc-sys-fs-binfmt_misc.automount
        modified:   units/systemd-binfmt.service.in
        modified:   units/systemd-udevd.service.in

追跡されていないファイル:
  (use "git add <file>..." to include in what will be committed)
        .pc/
        patches/

no changes added to commit (use "git add" and/or "git commit -a")

以下の一番最後のコマンドでパッチが作れる

# 該当ファイルが3つある
$ git status | grep journal
        modified:   src/journal-remote/journal-remote-write.c
        modified:   src/journal/journald-server.c
        modified:   src/libsystemd/sd-journal/journal-file.c

# modified:をトリミング
$ git status | grep journal | sed "s/modified://"
           src/journal-remote/journal-remote-write.c
           src/journal/journald-server.c
           src/libsystemd/sd-journal/journal-file.c

# 3ファイル分を1行で表示
$ git status | grep journal | sed "s/modified://" | xargs
src/journal-remote/journal-remote-write.c src/journal/journald-server.c src/libsystemd/sd-journal/journal-file.c

# パッチを作る
$ git diff $(git status | grep journal | sed "s/modified://" | xargs) > modified.patch

patchファイルの適応方法

patch -p(数字) < パッチファイル
  • -p0:パッチファイル内のパスをそのまま使用
  • -p1:パッチファイル内のパスの先頭1つを無視する
  • -p2:パスの先頭2つを無視する

CPU

使用してるCPU数が知りたい

$ lscpu
...(省略)
CPU:                                   20
  オンラインになっている CPU のリスト: 0-19
...(省略)

以下でも可能

$ cat /proc/cpuinfo

使用するCPU数を変更したい

$ sudo echo 0 > /sys/devices/system/cpu/cpuX/online

cpuXのXは数字で、onlineに0を書き込むと無効、1を書き込むと有効

各プロセスのスケジューリングポリシーが知りたい

$ chrt -p <PID>

指定パスが「/」直下にマウントされてるか確認する方法

sample.c
#include <linux/platform_device.h>
#include <linux/namei.h>

static char *filepath = "/";
module_param(filepath, charp, 0644);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Author");
MODULE_DESCRIPTION("A simple example Linux module.");

static int search_path(struct path *pathinfo)
{
	int ret = kern_path(filepath, LOOKUP_FOLLOW, pathinfo);
	if (!ret)
	{
		pr_info("%s:パス取得成功:%d\n", filepath, ret);
	}
	else
	{
		pr_info("%s:パス取得失敗:%d\n", filepath, ret);
	}
	return ret;
}
static int chK_mnt(struct path *pathinfo)
{
	int ret = 0;

	/*
	pathinfo->mntは、指定されたパスのマウント情報を指します。
	pathinfo->mnt->mnt_sbは、そのマウント情報に関連付けられたスーパーブロックを指します。
	pathinfo->mnt->mnt_sb->s_rootは、そのスーパーブロックのルートディレクトリ(マウントポイントのルート)を指します。
	pathinfo->dentryは、指定されたパスのディレクトリエントリを指します。
	*/
	if (pathinfo->mnt->mnt_sb->s_root == pathinfo->dentry)
	{
		pr_info("%s:マウント済\n", filepath);
	}
	else
	{
		ret = -1;
		pr_info("%s:未マウント\n", filepath);
	}
	return ret;
}

static int __init hello_init(void)
{
	struct path pathinfo;
	int ret = search_path(&pathinfo);
	if (!ret)
	{
		chK_mnt(&pathinfo);
	}
	path_put(&pathinfo);
	return 0;
}
static void __exit hello_exit(void)
{
	pr_info("Goodbye!\n");
}

module_init(hello_init);
module_exit(hello_exit);

コマンド Tips

lsコマンド

# 縦に並べる「ハイフンイチ」
$ ls -1

mkdirコマンド

# -pをつけると、既にディレクトリがある場合でもエラーにならない。(何もしない)
mkdir -p <既存ディレクトリ>

installコマンド

ファイルコピー

  • ディレクトリが存在しない場合は作成(-D)
  • 複数ファイルをコピー(-t)。ワイルドカード使える
  • 権限変更(-m)
$ install -D -t install_dir -m0644 *.txt

grepコマンド

  • 一致しないものを検索(-v)

nmcliコマンド

Wifi設定関連

# scanと結果表示
$ nmcli device wifi list
# 接続
$ sudo nmcli device wifi connect <SSID> password "<password>"

xargsコマンド

  • -rは引数がない場合はコマンドを実行しないの意味
# メインブランチしかない場合は、引数がなくなるので、git branch -dは実行されない
$ git branch
* main
$ git br | grep -v "^\*" | xargs -r git branch -d

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?